Allow embiggener to give mag ammo like in the sidemods.
This commit is contained in:
parent
186229c421
commit
6baa8b8215
8 changed files with 127 additions and 75 deletions
|
|
@ -354,6 +354,59 @@ Class HammerspaceEmbiggener : Inventory
|
|||
}
|
||||
}
|
||||
}
|
||||
// do the same for mag ammo, in a separate loop
|
||||
for ( int i=0; i<AllActorClasses.Size(); i++ )
|
||||
{
|
||||
let type = (class<MagAmmo>)(AllActorClasses[i]);
|
||||
if ( !type || (type.GetParentClass() != 'MagAmmo') ) continue;
|
||||
let magitem = MagAmmo(other.FindInventory(type));
|
||||
int amount = GetDefaultByType(type).BackpackAmount*self.Amount;
|
||||
if ( traded ) amount = 0;
|
||||
if ( amount < 0 ) amount = 0;
|
||||
int mags = amount/GetDefaultByType(type).ClipSize;
|
||||
amount = amount%GetDefaultByType(type).ClipSize;
|
||||
if ( !magitem )
|
||||
{
|
||||
// The player did not have the magitem. Add it.
|
||||
magitem = MagAmmo(Spawn(type));
|
||||
magitem.Amount = amount;
|
||||
magitem.AttachToOwner(other);
|
||||
// by this point, we assume that the parent ammo pointer is valid, so...
|
||||
let ammoitem = magitem.pamo;
|
||||
// append some mags to it
|
||||
if ( ammoitem.Amount < ammoitem.MaxAmount )
|
||||
{
|
||||
if ( (ammoitem.Amount > 0) && (ammoitem.Amount+mags < 0) )
|
||||
ammoitem.Amount = int.max;
|
||||
else ammoitem.Amount += mags;
|
||||
if ( (ammoitem.Amount > ammoitem.MaxAmount) && !sv_unlimited_pickup )
|
||||
ammoitem.Amount = ammoitem.MaxAmount;
|
||||
}
|
||||
// we can't add extra mags, just max out the spare ammo
|
||||
else if ( mags > 0 ) magitem.Amount = min(magitem.MaxAmount,magitem.Amount+magitem.ClipSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( magitem.Amount+amount >= magitem.MaxAmount )
|
||||
{
|
||||
mags++;
|
||||
amount -= magitem.MaxAmount;
|
||||
}
|
||||
magitem.Amount += amount;
|
||||
let ammoitem = magitem.pamo;
|
||||
// append some mags to it
|
||||
if ( ammoitem.Amount < ammoitem.MaxAmount )
|
||||
{
|
||||
if ( (ammoitem.Amount > 0) && (ammoitem.Amount+mags < 0) )
|
||||
ammoitem.Amount = int.max;
|
||||
else ammoitem.Amount += mags;
|
||||
if ( (ammoitem.Amount > ammoitem.MaxAmount) && !sv_unlimited_pickup )
|
||||
ammoitem.Amount = ammoitem.MaxAmount;
|
||||
}
|
||||
// we can't add extra mags, just max out the spare ammo
|
||||
else if ( mags > 0 ) magitem.Amount = min(magitem.MaxAmount,magitem.Amount+magitem.ClipSize);
|
||||
}
|
||||
}
|
||||
self.Amount = min(self.Amount,MaxAmount);
|
||||
if ( GetParentClass() == 'HammerspaceEmbiggener' )
|
||||
{
|
||||
|
|
@ -403,6 +456,31 @@ Class HammerspaceEmbiggener : Inventory
|
|||
if ( (i.Amount > i.MaxAmount) && !sv_unlimited_pickup )
|
||||
i.Amount = i.MaxAmount;
|
||||
}
|
||||
if ( traded ) return true;
|
||||
// give spare mag ammo separately
|
||||
for ( Inventory i=Owner.Inv; i; i=i.Inv )
|
||||
{
|
||||
if ( !(i is 'MagAmmo') ) continue;
|
||||
int amount = MagAmmo(i).BackpackAmount*item.Amount;
|
||||
int mags = amount/MagAmmo(i).ClipSize;
|
||||
amount = amount%MagAmmo(i).ClipSize;
|
||||
if ( i.Amount+amount >= MagAmmo(i).ClipSize )
|
||||
{
|
||||
mags++;
|
||||
amount -= MagAmmo(i).ClipSize;
|
||||
}
|
||||
i.Amount += amount;
|
||||
Ammo a = MagAmmo(i).pamo;
|
||||
if ( a.Amount < a.MaxAmount )
|
||||
{
|
||||
if ( (a.Amount > 0) && (a.Amount+mags < 0) )
|
||||
a.Amount = int.max;
|
||||
else a.Amount += mags;
|
||||
if ( (a.Amount > a.MaxAmount) && !sv_unlimited_pickup )
|
||||
a.Amount = a.MaxAmount;
|
||||
}
|
||||
else if ( mags > 0 ) i.Amount = min(i.MaxAmount,i.Amount+MagAmmo(i).ClipSize);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// new ammo suddenly added? upgrade it (this shouldn't happen unless fucky scripting has been involved)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue