如果你想在 InventoryManager 中编写所有代码,它看起来像
simulated function bool AddInventory(Inventory NewItem, optional bool bDoNotActivate){
local Inventory Item, LastItem;
// The item should not have been destroyed if we get here.
if( (NewItem != None) && !NewItem.bDeleteMe )
{
//if weapon - work in personal weapon function
if(Weapon(NewItem) != none)
return AddItemWeapon(NewItem, bDoNotActivate);
// if we don't have an inventory list, start here
if( InventoryChain == None )
{
InventoryChain = newItem;
}
else
{
// Skip if already in the inventory.
for (Item = InventoryChain; Item != None; Item = Item.Inventory)
{
if( Item == NewItem )
{
return FALSE;
}
LastItem = Item;
}
LastItem.Inventory = NewItem;
}
//Edited by Matt Kerns
`LogInv("adding" @ NewItem @ "bDoNotActivate:" @ bDoNotActivate);
`Log ("Added to inventory!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
NewItem.SetOwner( Instigator );
NewItem.Instigator = Instigator;
NewItem.InvManager = Self;
NewItem.GivenTo( Instigator, bDoNotActivate);
// Trigger inventory event
Instigator.TriggerEventClass(class'SeqEvent_GetInventory', NewItem);
return TRUE;
}
return FALSE;
}
模拟函数 AddItemWeapon(Inventory NewItem, optional bool bDoNotActivate) {
local Inventory Item, LastItem;
local Weapon WeaponNewItem;
WeaponNewItem= Weapon(NewItem);
// The item should not have been destroyed if we get here.
if( (NewItem != None) && !NewItem.bDeleteMe )
{
// if we don't have an inventory list, start here
if( InventoryChain == None )
{
InventoryChain = newItem;
}
else
{
//look for our group
for (Item = InventoryChain; Item != None; Item = Item.Inventory){
if(Weapon(Item) != none && Weapon(Item).Group == WeaponNewItem.Group){
RemoveFromInventory(Item);
break;
}
}
// Skip if already in the inventory.
for (Item = InventoryChain; Item != None; Item = Item.Inventory)
{
if( Item == NewItem )
{
return FALSE;
}
LastItem = Item;
}
LastItem.Inventory = NewItem;
}
//Edited by Matt Kerns
`LogInv("adding" @ NewItem @ "bDoNotActivate:" @ bDoNotActivate);
`Log ("Added to inventory!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
NewItem.SetOwner( Instigator );
NewItem.Instigator = Instigator;
NewItem.InvManager = Self;
NewItem.GivenTo( Instigator, bDoNotActivate);
// Trigger inventory event
Instigator.TriggerEventClass(class'SeqEvent_GetInventory', NewItem);
return TRUE;
}
return FALSE;
}
如果您的游戏使用网络并复制库存,这是最好的方法。如果没有,你可以简单地写一些像
simulated function AddItemWeapon(Inventory NewItem, optional bool bDoNotActivate){
local Inventory Item, LastItem;
local Weapon WeaponNewItem;
local bool bAddNewWeapon;
bAddNewWeapon = true;
WeaponNewItem = Weapon(NewItem);
// The item should not have been destroyed if we get here.
if( (NewItem != None) && !NewItem.bDeleteMe )
{
// if we don't have an inventory list, start here
if( InventoryChain == None )
{
InventoryChain = newItem;
}
else
{
//look for our group
for (Item = InventoryChain; Item != None; Item = Item.Inventory){
if(Weapon(Item) != none && Weapon(Item).Group == WeaponNewItem.Group){
NewItem.Inventory = Item.Inventory;
bAddNewWeapon = false;
RemoveFromInventory(Item);
break;
}
LastItem = Item;
}
if(bAddNewWeapon){
for (Item = InventoryChain; Item != None; Item = Item.Inventory){
LastItem = Item;
}
}
LastItem.Inventory = NewItem;
}
但我确信这是不好的方式。您应该编写将保存所有使用过的武器组并仅使用 InventoryManager 作为存储的类