Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ArtifactWeaponCrafter extends ArtifactCraftWeapon;
- //DependsOn(MapAllowedWeapons);
- struct AvailableWeaponsStruct
- {
- var() class<Weapon> WeaponClass;
- var() int Chance;
- var() bool AdvancedSpawn;
- };
- var array< AvailableWeaponsStruct > AvailableWeapons;
- var MapAllowedWeapons WeaponsInfo;
- var MapAllowedWeapons DefWeaponsInfo;
- var string MapName;
- var bool bIsMechanic;
- var bool bVerified;
- var bool bInitDone;
- var int iLastSelected;
- var float AltLastUseTime;
- var bool bHardMode;
- function GiveTo( pawn Other, optional Pickup Source )
- {
- local MapAllowedWeapons WNfo;
- local string s;
- local int is;
- //log (self $ " Hi ");
- Instigator = Other;
- if ( Other.AddInventory( Self ) )
- {
- //log (self $ " Hi Hi ");
- GotoState('');
- s = string(self);
- is = InStr(s,".");
- s = Left(s,is);
- //log (self $ " 0 " $ s);
- DefWeaponsInfo = class'ArtifactWeaponCrafter'.default.DefWeaponsInfo;
- MapName = class'ArtifactWeaponCrafter'.default.MapName;
- //log (self $ " 1 " $ DefWeaponsInfo $ " <- " $ class'ArtifactWeaponCrafter'.default.DefWeaponsInfo);
- if(Source == None && MapName != s)
- {
- forEach DynamicActors( class'MapAllowedWeapons', WNfo )
- {
- if (WNfo.AllowedWeapons.length > 0 &&( (WNfo.AllowedWeapons[0].AllowedWeaponsArray.length > 0 && WNfo.AllowedWeapons[0].AllowedWeaponsArray[0].WeaponClass != None) || (WNfo.AllowedWeapons.length > 1 && WNfo.AllowedWeapons[1].AllowedWeaponsArray.length > 0 && WNfo.AllowedWeapons[1].AllowedWeaponsArray[0].WeaponClass != None) ) )
- {
- WeaponsInfo = WNfo;
- class'ArtifactWeaponCrafter'.default.DefWeaponsInfo = WNfo;
- DefWeaponsInfo = None;
- //log (self $ " 2 " $ class'ArtifactWeaponCrafter'.default.DefWeaponsInfo);
- }
- //log (self $ " 2.5 ");
- break;
- }
- class'ArtifactWeaponCrafter'.default.MapName = s;
- }
- if (Source == None && DefWeaponsInfo != None)
- WeaponsInfo = DefWeaponsInfo;
- if(Source == None && WeaponsInfo!= None)
- bHardMode = WeaponsInfo.bHardMode;
- if(ArtifactWeaponCrafterPickup(Source) != None)
- bHardMode = ArtifactWeaponCrafterPickup(Source).bHardMode;
- //log (self $ " 3 " $ WeaponsInfo);
- //InvMetal = InvScrapMetal(Other.FindInventoryType(class'InvScrapMetal'));
- if (!bInitDone)
- Init(Other, Source);
- }
- else
- {
- log (self $ " ded ");
- Destroy();
- }
- }
- function bool HandlePickupQuery(Pickup Item)
- {
- local int i,k,j,L;
- local class<Weapon> WepClass;
- local bool bDuplicate;
- local ArtifactWeaponCrafterPickup Source;
- if (item.InventoryType == class)
- {
- L = -1;
- k = -1;
- Source = ArtifactWeaponCrafterPickup(Item);
- if (Source != None)
- {
- if(!Source.bHardMode && bHardMode)
- bHardMode = false;
- L=AvailableWeapons.length;
- for( k=L; i < Source.AllowedWeapons.length; i++ )
- {
- bDuplicate = false;
- WepClass = Source.AllowedWeapons[i].WeaponClass;
- for(j=0; j < L ; j++)
- {
- if (WepClass==AvailableWeapons[j].WeaponClass)
- {bDuplicate = true;
- j=L;}
- }
- if (!Source.AllowedWeapons[i].AdvancedSpawn && !bDuplicate)
- {
- AvailableWeapons.length = AvailableWeapons.length + 1;
- AvailableWeapons[k].WeaponClass = WepClass;
- AvailableWeapons[k].Chance = Source.AllowedWeapons[i].Chance;
- k++;
- }
- else if (Source.AllowedWeapons[i].AdvancedSpawn && bIsMechanic)
- {
- AvailableWeapons.length = AvailableWeapons.length + 1;
- AvailableWeapons[k].WeaponClass = WepClass;
- AvailableWeapons[k].Chance = Source.AllowedWeapons[i].Chance;
- AvailableWeapons[k].AdvancedSpawn = true;
- k++;
- }
- }
- }
- if (k > 0 && L >= 0 && k > L)
- {
- Item.AnnouncePickup(Pawn(Owner));
- Item.SetRespawn();
- return true;
- }
- else
- return true;
- }
- if ( Inventory == None ) // Next in inventory chain
- return false;
- return Inventory.HandlePickupQuery(Item);
- }
- function Init(pawn Other, optional Pickup Pickup)
- {
- local RPGPlayerDataObject Data;
- local int i,j,k;
- local ArtifactWeaponCrafterPickup Source;
- Source = ArtifactWeaponCrafterPickup(Pickup);
- if (!bIsMechanic)
- Data = RPGPlayerDataObject(FindObject("Package." $ Other.PlayerReplicationInfo.PlayerName, class'RPGPlayerDataObject'));
- if (Data != None && Data.Abilities.length > 0 && class<RPGClass>(Data.Abilities[0]) != None && class<RPGClass>(Data.Abilities[0]).default.ClassIDNumber == 5)
- bIsMechanic = true;
- if (WeaponsInfo != None)
- {
- if (WeaponsInfo.AllowedWeapons.length > 0)
- for( i=0; i < WeaponsInfo.AllowedWeapons[0].AllowedWeaponsArray.length; i++ )
- {
- AvailableWeapons.length = AvailableWeapons.length + 1;
- AvailableWeapons[i].WeaponClass = WeaponsInfo.AllowedWeapons[0].AllowedWeaponsArray[i].WeaponClass;
- AvailableWeapons[i].Chance = WeaponsInfo.AllowedWeapons[0].AllowedWeaponsArray[i].Chance;
- }
- //log (self $ " Init 1 Is mechanic= " $ bIsMechanic $ ", " $ data);
- if(bIsMechanic)
- {
- //log (self $ " Init 2 " $ WeaponsInfo.AllowedWeapons[1].AllowedWeaponsArray.length);
- if (WeaponsInfo.AllowedWeapons.length > 1)
- for( j=i; k < WeaponsInfo.AllowedWeapons[1].AllowedWeaponsArray.length; j++ )
- {
- AvailableWeapons.length = AvailableWeapons.length + 1;
- AvailableWeapons[j].WeaponClass = WeaponsInfo.AllowedWeapons[1].AllowedWeaponsArray[k].WeaponClass;
- AvailableWeapons[j].Chance = WeaponsInfo.AllowedWeapons[1].AllowedWeaponsArray[k].Chance;
- AvailableWeapons[j].AdvancedSpawn = true;
- k++;
- }
- }
- }
- else if (Source != None)
- {
- for( i=0; i < Source.AllowedWeapons.length; i++ )
- {
- if (!Source.AllowedWeapons[i].AdvancedSpawn)
- {
- AvailableWeapons.length = AvailableWeapons.length + 1;
- AvailableWeapons[k].WeaponClass = Source.AllowedWeapons[i].WeaponClass;
- AvailableWeapons[k].Chance = Source.AllowedWeapons[i].Chance;
- k++;
- }
- else if (bIsMechanic)
- {
- AvailableWeapons.length = AvailableWeapons.length + 1;
- AvailableWeapons[k].WeaponClass = Source.AllowedWeapons[i].WeaponClass;
- AvailableWeapons[k].Chance = Source.AllowedWeapons[i].Chance;
- AvailableWeapons[k].AdvancedSpawn = true;
- k++;
- }
- }
- }
- bInitDone = true;
- }
- function bool GetUsability()
- {
- //Can't use this if you don't have enough adrenaline...
- if (Instigator.Controller.Adrenaline < GetCost() )
- {
- Instigator.ReceiveLocalizedMessage(MessageClass, GetCost(), None, None, Class);
- return false;
- }
- //Can't use this if we don't have scrap metal
- if (InvMetal != None && InvMetal.ScrapMetal[0] <= 0 && InvMetal.ScrapMetal[1] <= 0 && InvMetal.ScrapMetal[2] <= 0 && InvMetal.ScrapMetal[3] <= 0 && InvMetal.ScrapMetal[4] <= 0)
- {
- Instigator.ReceiveLocalizedMessage(MessageClass, 1000, None, None, Class);
- return false;
- }
- return true;
- }
- function Activate()
- {
- local int i;
- for( i=0; i < AvailableWeapons.length; i++ )
- {
- Instigator.ClientMessage("[" $ i $ "] = " $ string(AvailableWeapons[i].WeaponClass) $ " Chance= " $ AvailableWeapons[i].Chance ); //.Default.FriendlyName);
- if (AvailableWeapons[i].AdvancedSpawn)
- Instigator.ClientMessage("is complicated");
- }
- }
- function AltActivate(optional string Param)
- {
- local float TimeDelta;
- local int i,CT,R,F,CS;
- TimeDelta = Level.TimeSeconds - AltLastUseTime;
- if (Level.TimeSeconds - AltLastUseTime < UseDelay)
- {
- Instigator.ReceiveLocalizedMessage(MessageClass, 5000 + UseDelay - TimeDelta, None, None, Class);
- bActive = false;
- GotoState('');
- return;
- }
- AltLastUseTime = Level.TimeSeconds;
- if (InvMetal == None)
- InvMetal = InvScrapMetal(Instigator.FindInventoryType(class'InvScrapMetal'));
- if (!bVerified && InvMetal == None)
- {
- if (bIsMechanic)
- log (self $ " Mechanic RPGClass detection error ");
- for( i=0; i < AvailableWeapons.length; i++ )
- if(AvailableWeapons[i].AdvancedSpawn)
- {
- AvailableWeapons.Remove(i, 1);
- i--;
- }
- bVerified = true;
- }
- if (!bIsFree && !GetUsability())
- return;
- for( i=0; i < AvailableWeapons.length; i++ )
- CT += AvailableWeapons[i].Chance;
- if( CT <= 0 )
- {
- log (self $ " Chance total <= 0 ");
- return;
- }
- R = Rand(CT);
- F = CT - R;
- //log (self $ " AltAct 1 " $ InvMetal);
- for( i=0; i < AvailableWeapons.length; i++ )
- {
- CS += AvailableWeapons[i].Chance;
- if(F <= CS)
- {
- WeaponClass = AvailableWeapons[i].WeaponClass;
- iLastSelected = i;
- Super.AltActivate();
- break;
- }
- }
- }
- function bool shouldBreak()
- {
- if (InvMetal == None)
- Return true;
- Return false;
- }
- function PayUp ()
- {
- local int i;
- Instigator.Controller.Adrenaline -= GetCost();
- if (Instigator.Controller.Adrenaline < 0)
- Instigator.Controller.Adrenaline = 0;
- //Remove scrap metal
- if (InvMetal != None)
- {
- i = 4;
- while (InvMetal.ScrapMetal[i] <= 0 && i >= 0)
- i--;
- InvMetal.RemoveMetal(i);
- }
- if (AvailableWeapons[iLastSelected].AdvancedSpawn || bHardMode)
- {
- AvailableWeapons.Remove(iLastSelected, 1);
- }
- if ( shouldBreak() )
- {
- Destroy();
- Instigator.NextItem();
- Return;
- }
- }
- defaultproperties
- {
- ChangelingClass=Class'SillyRPG.XIsAChangeling'
- AbilityLevel=1
- UseDelay=2
- WeaponClass=None
- bIsFree=false
- bIsDropped=true
- MinActivationTime=0.000001
- ActivateSound=Sound'WeaponSounds.BaseGunTech.BReload2'
- PickupClass=Class'SillyRPGv1-1.ArtifactWeaponCrafterPickup'
- IconMaterial=Texture'ME_RPGExpansion.Icons.CraftSpiderMines'
- ItemName="Weapon Crafter"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement