|
这是dota的系统的简化版本,需在cjass下编译,需include“cj_types.j”
两个重要函数
void StoreItemData(int index, string name, int itemId, int fakeItemId,int stack,int stack max)
void StoreAssembleFormula(int index,string name,int assembleindex,int index1,int index2,int index3,int index4,int index5,int index6,int index7)
StoreItemData是存储物品信息,第一个参数是第几个物品,作为第二个函数的参数,第二个参数是物品名字(只是注释而已),第三个参数是有效果的物品,第四个是商店里卖得假物品(类型应为可充),第五个是物品使用次数(可选填),第六个是最大使用次数(选填)你可以对
struct ItemStruct{
int Id
int fId
int Stack
int StackMax
string RF
}
ItemStruct array Item
这个结构进行扩展,比如存储物品的图标,cd,与之冲突的物品,来让起存储更多东西,StoreItemData函数的两个参数stack,stackmax可以不填写,进行了函数重载.
StoreAssembleFormula是存储物品合成公式,int参数是结构Item数组的对应下标,也就是第一个函数的第一个参数,assemble是合成目标(第几个物品)。剩下来的是合成需要物品的下标(他们是第几个物品)。
StoreAssembleFormula进行了函数重载,但最少需要五个参数(第几个公式,公式名字,合成目标,需求1,需求2)
以下是代码(使用VJASS和Cjass混编)
[jass]
globals
trigger ItemCompose = CreateTrigger()
integer FormulaCount = 0
integer ItemCount = 0
endglobals
struct ItemStruct{
int Id
int fId
int Stack
int StackMax
string RF
}
ItemStruct array Item
struct FormulaStruct{
int array itemindex [9]
}
FormulaStruct array Formula
void StoreItemData(int index, string name, int itemId, int fakeItemId,int stack,int stack
max){
int i
ItemCount++
i = ItemCount
Item.Id = itemId
Item.fId = fakeItemId
Item.RF = ""
}
#define{
StroeItemData(index,name,itemId,fakeItemid,stack,maxstack) = Stroe##ItemData
(index,name,itemId,fakeItemid,stack,maxstack)
StroeItemData(index,name,itemId,fakeItemid,stack) = Stroe##ItemData
(index,name,itemId,fakeItemid,stack,0)
StroeItemData(index,name,itemId,fakeItemid) = Stroe##ItemData
(index,name,itemId,fakeItemid,0,0)
}
void StoreAssembleFormula(int index,string name,int assembleindex,int index1,int index2,int
index3,int index4,int index5,int index6,int index7){
integer i = 1
boolean k = true
integer l = 1
FormulaCount++
Formula[FormulaCount].itemindex[1] = index1
Formula[FormulaCount].itemindex[2] = index2
Formula[FormulaCount].itemindex[3] = index3
Formula[FormulaCount].itemindex[4] = index4
Formula[FormulaCount].itemindex[5] = index5
Formula[FormulaCount].itemindex[6] = index6
Formula[FormulaCount].itemindex[7] = index7
Formula[FormulaCount].itemindex[8] = assembleindex
loop
exitwhen l > 7
k = k && ( Formula[FormulaCount].itemindex[l] != 0 )
if ( (Item[Formula[FormulaCount].itemindex[l]].RF== null) and k ) then
Item[Formula[FormulaCount].itemindex[l]].RF = I2S(FormulaCount )
elseif k then
Item[Formula[FormulaCount].itemindex[l]].RF = Item[Formula
[FormulaCount].itemindex[l]].RF + "," + I2S(FormulaCount )
else
return
endif
set l = l + 1
endloop
}
int GetItemIndex(item whichItem){
integer itemTypeId = GetItemTypeId(whichItem)
integer i = 1
loop
exitwhen i > ItemCount
if Item.Id == itemTypeId or Item.fId == itemTypeId then
return i
endif
i++
endloop
return 0
}
#define{
StoreAssembleFormula
(index,name,assembleindex,index1,index2,index3,index4,index5,index6,index7) =
StoreAssemble##Formula
(index,name,assembleindex,index1,index2,index3,index4,index5,index6,index7)
StoreAssembleFormula(index,name,assembleindex,index1,index2,index3,index4,index5,index6)
= StoreAssemble##Formula
(index,name,assembleindex,index1,index2,index3,index4,index5,index6,0)
StoreAssembleFormula(index,name,assembleindex,index1,index2,index3,index4,index5) =
StoreAssemble##Formula(index,name,assembleindex,index1,index2,index3,index4,index5,0,0)
StoreAssembleFormula(index,name,assembleindex,index1,index2,index3,index4) =
StoreAssemble##Formula(index,name,assembleindex,index1,index2,index3,index4,0,0,0)
StoreAssembleFormula(index,name,assembleindex,index1,index2,index3) =
StoreAssemble##Formula(index,name,assembleindex,index1,index2,index3,0,0,0,0)
StoreAssembleFormula(index,name,assembleindex,index1,index2) = StoreAssemble##Formula
(index,name,assembleindex,index1,index2,0,0,0,0,0)
}
int GetUnitEmptySlotIndex(unit whichUnit){
local integer i = 0
loop
exitwhen i > 5
if UnitItemInSlot(whichUnit, i) == null then
return i + 1
endif
i++
endloop
return -1
}
int FindItem(unit whichUnit, integer formulaItemIndex, integer newItemIndex, string
shelter){
local integer i = 0
local item indexItem
loop
exitwhen i > 5
if SubString(shelter, i, i + 1) == "F" then
indexItem = UnitItemInSlot(whichUnit, i)
if indexItem != null and GetItemTypeId(indexItem) == Item[formulaItemIndex].Id
then
set indexItem = null
return i + 1
endif
endif
i++
endloop
if SubString(shelter, 6, 7) == "F" and newItemIndex != 0 then
if Item[formulaItemIndex].Id == Item[newItemIndex].Id then
set indexItem = null
return 7
endif
endif
set indexItem = null
return 0
}
item GetItemOfTypeFromUnit(unit whichUnit, integer itemId){
integer i = 0
item indexItem
loop
exitwhen i > 5
set indexItem = UnitItemInSlot(whichUnit, i)
if GetItemTypeId(indexItem) == itemId then
return indexItem
endif
i++
endloop
indexItem = null
return null
}
bool CheckStack(unit whichUnit, integer itemIndex, item whichItem){
integer i = 0
item indexItem
integer charge1
integer charge2
loop
exitwhen i > 5
set indexItem = UnitItemInSlot(whichUnit, i)
if GetItemTypeId(indexItem) == Item[itemIndex].Id and indexItem != whichItem then
if GetItemTypeId(whichItem) == Item[itemIndex].fId then
if GetItemPlayer(whichItem) == Player(15) then
charge1 = Item[itemIndex].Stack
else
charge1 = GetItemUserData(whichItem)
endif
else
charge1 = GetItemCharges(whichItem)
endif
charge2 = GetItemCharges(indexItem)
if charge1 + charge2 <= Item[itemIndex].StackMax then
SetItemCharges(indexItem, charge1 + charge2)
RemoveItem(whichItem)
indexItem = null
return true
endif
endif
i++
endloop
indexItem = null
return false
}
item CheckFormula(unit whichUnit, integer itemIndex, item whichItem, integer formulaIndex){
local integer slot
local string shelter = "FFFFFFF"
local integer i = 1
loop
exitwhen i > 7
if Formula[formulaIndex].itemindex != 0 then
slot = FindItem(whichUnit, Formula[formulaIndex].itemindex, itemIndex,
shelter)
if slot == 0 then
return null
else
shelter = SubString(shelter, 0, slot - 1) + "T" + SubString(shelter, slot,
7)
endif
endif
i++
endloop
set i = 1
loop
exitwhen i > 7
if Formula[formulaIndex].itemindex != 0 then
RemoveItem(GetItemOfTypeFromUnit(whichUnit, Item[Formula
[formulaIndex].itemindex].Id))
endif
i++
endloop
RemoveItem(whichItem)
whichItem = CreateItem(Item[Formula[formulaIndex].itemindex[8]].Id, 0, 0)
return whichItem
}
void ItemAssembleSpecial(unit whichUnit){
local integer Int = GetRandomInt(1,3)
if Int == 1 then
call DestroyEffect(AddSpecialEffectTargetUnitBJ("origin", whichUnit, "Abilities\
\Spells\\Items\\AIem\\AIemTarget.mdl"))
elseif Int == 2 then
call DestroyEffect(AddSpecialEffectTargetUnitBJ("origin", whichUnit,"Abilities\
\Spells\\Items\\AIim\\AIimTarget.mdl"))
elseif Int == 3 then
call DestroyEffect(AddSpecialEffectTargetUnitBJ("origin", whichUnit,"Abilities\
\Spells\\Items\\AIsm\\AIsmTarget.mdl"))
endif
}
item CheckAssemble(unit whichUnit, integer itemIndex, item whichItem){
string formula = Item[itemIndex].RF
integer i = 0
integer array formulaIndexes
integer lastIndex = 0
integer length
item assembleItem = null
if formula == "" then
return null
endif
length = StringLength(formula)
loop
exitwhen i >= length
if SubString(formula, i, i + 1) != "," then
lastIndex++
formulaIndexes[lastIndex] = S2I(SubString(formula, i, i + 1))
i++
else
i++
endif
endloop
set i = 1
loop
exitwhen i > lastIndex
assembleItem = CheckFormula(whichUnit, itemIndex, whichItem, formulaIndexes)
if assembleItem != null then
whichItem = CheckAssemble(whichUnit, GetItemIndex(assembleItem), assembleItem)
if whichItem != null then
call ItemAssembleSpecial(whichUnit)
return whichItem
else
ItemAssembleSpecial(whichUnit)
return assembleItem
endif
endif
i++
endloop
return assembleItem
}
void ItemActions(){
item whichItem = GetManipulatedItem()
unit whichUnit = GetManipulatingUnit()
player whichPlayer = GetOwningPlayer(whichUnit)
player itemOwner = GetItemPlayer(whichItem)
integer itemIndex = GetItemIndex(whichItem)
integer emptySlot
//timer tm
real x
real y
boolean moveToUnit = false
item assembleItem
boolean notCheckAssemble = false
integer charge
//local integer conflictIndex
call DisableTrigger(ItemCompose)
if itemIndex == 0 then
call EnableTrigger(ItemCompose)
return
endif
//call BJDebugMsg("PickUp An Item Own By Player " + I2S(GetPlayerId(itemOwner)))
if itemOwner == Player(15) then
assembleItem = CheckAssemble(whichUnit, itemIndex, whichItem)
if assembleItem != null then
call RemoveItem(whichItem)
set whichItem = assembleItem
set itemIndex = GetItemIndex(whichItem)
call SetItemCharges(whichItem, Item[itemIndex].Stack)
else
set assembleItem = CreateItem(Item[itemIndex].Id, 0, 0)
call RemoveItem(whichItem)
set whichItem = assembleItem
endif
set moveToUnit = true
if CheckStack( whichUnit,itemIndex,whichItem) then
set moveToUnit = false
endif
endif
if itemOwner == Player(15) or itemOwner == whichPlayer then
call SetItemPlayer(whichItem, whichPlayer, false)
else
call SetItemPlayer(whichItem, itemOwner, false)
endif
if moveToUnit == true then
call DisableTrigger(ItemCompose)
call UnitAddItem(whichUnit, whichItem)
call EnableTrigger(ItemCompose)
endif
set whichItem = null
set whichUnit = null
set whichPlayer = null
set itemOwner = null
set assembleItem = null
call EnableTrigger(ItemCompose)
}
[/jass] |
|