// the give/take cheat, oh boy extend Class Demolitionist { void CheatGive_Health( int amount = 0 ) { player.health = health = (amount>0)?(health+amount):default.health; } void CheatGive_Backpack() { let def = GetDefaultByType('HammerspaceEmbiggener'); GiveInventory('TradedHammerspaceEmbiggener',def.MaxAmount,true); } void CheatGive_Ammo() { // Max out all mod ammo foreach ( cls:AllActorClasses ) { let type = (class)(cls); if ( !type || type.IsAbstract() || (type.GetParentClass() != 'SWWMAmmo') ) continue; let ammoitem = Ammo(FindInventory(type)); if ( !ammoitem ) { // Add it first if not found ammoitem = Ammo(Spawn(type)); ammoitem.Amount = 0; ammoitem.AttachToOwner(self); } // Don't give spares unless we own a Candy Gun, for consistency if ( (type is 'CandyGunSpares') && !FindInventory('CandyGun') ) continue; // Top up ammoitem.Amount = ammoitem.MaxAmount; // Does it have mag ammo? let sammoitem = SWWMAmmo(ammoitem); if ( !sammoitem || !sammoitem.MagAmmoType ) continue; let magitem = MagAmmo(FindInventory(sammoitem.MagAmmoType)); if ( !magitem ) { // Add it first if not found (shouldn't happen) magitem = MagAmmo(Spawn(sammoitem.MagAmmoType)); magitem.AttachToOwner(self); } // Top up magitem.Amount = magitem.MaxAmount; } } void CheatGive_Armor() { // only give armors that have spares associated foreach ( cls:AllActorClasses ) { let type = (Class)(cls); if ( !type || type.IsAbstract() || (type == 'SWWMSpareArmor') ) continue; if ( GetReplacement(type) != type ) continue; let def = GetDefaultByType(type); let armo = SWWMArmor(FindInventory(def.giveme)); if ( !armo ) { armo = SWWMArmor(Spawn(def.giveme)); armo.AttachToOwner(self); } armo.Amount = armo.MaxAmount; } } void CheatGive_Keys() { foreach ( cls:AllActorClasses ) { let type = (Class)(cls); if ( !type ) continue; let keyitem = GetDefaultByType(type); if ( !keyitem.special1 ) continue; let rep = GetReplacement(type); // handle replaced keys if ( !(rep is 'Key') ) continue; // iwad restrictions (vanilla doesn't care, but here they'll show in the inventory) if ( !(gameinfo.gametype&GAME_HERETIC) && ((rep is 'SWWMKeyGreen') || (rep is 'SWWMKeyBlue') || (rep is 'SWWMKeyYellow')) ) continue; if ( !(gameinfo.gametype&GAME_DOOM) && ((rep is 'SWWMRedCard') || (rep is 'SWWMBlueCard') || (rep is 'SWWMYellowCard')) ) continue; let item = Inventory(Spawn(rep)); SWWMHandler.KeyTagFix(item); if ( item is 'SWWMKey' ) SWWMKey(item).propagated = true; // no anim key_reentrant = true; if ( !item.CallTryPickup(self) ) item.Destroy(); key_reentrant = false; } } void CheatGive_Weapons() { let savedpending = player.PendingWeapon; foreach ( cls:AllActorClasses ) { let type = (class)(cls); if ( !type || (type == "Weapon") ) continue; // Don't give already owned weapons let owned = FindInventory(type); if ( owned && (owned.Amount >= owned.MaxAmount) ) continue; // Don't give replaced weapons unless the replacement was done by Dehacked. let rep = GetReplacement(type); if ( (rep == type) || (rep is "DehackedPickup") ) { // Give the weapon only if it is set in a weapon slot. if ( !player.weapons.LocateWeapon(type) ) continue; readonly def = GetDefaultByType(type); if ( !def.bCheatNotWeapon && def.CanPickup(self) ) GiveInventory(type,1,true); } } player.PendingWeapon = savedpending; } void CheatGive_Artifacts( int amount = 0 ) { foreach ( cls:AllActorClasses ) { let type = (class)(cls); if ( !type ) continue; let rep = GetReplacement(type); // don't give replaced items if ( rep != type ) continue; // no fabricators before hexen if ( !(gameinfo.gametype&GAME_HEXEN) && (type is 'AmmoFabricator') ) continue; // no barriers outside doom if ( !(gameinfo.gametype&GAME_DOOM) && (type is 'EBarrier') ) continue; // no gravity/tether outside raven if ( !(gameinfo.gametype&GAME_RAVEN) && ((type is 'GravitySuppressor') || (type is 'SafetyTether')) ) continue; // Don't give maxed items let owned = FindInventory(type); if ( owned && (owned.Amount >= owned.MaxAmount) ) continue; let def = GetDefaultByType(type); // must have INVBAR and a valid icon (also can't be a puzzle item) if ( !def.bINVBAR || !def.ShouldSpawn() || !def.Icon.isValid() || (type is 'PuzzleItem') ) continue; GiveInventory(type,(amount<=0)?def.MaxAmount:amount,true); } } void CheatGive_PuzzlePieces( int amount = 0 ) { foreach ( cls:AllActorClasses ) { let type = (class)(cls); if ( !type ) continue; let def = GetDefaultByType(type); if ( !def.Icon.isValid() ) continue; GiveInventory(type,(amount<=0)?def.MaxAmount:amount,true); } } void CheatGive_Collectibles() { foreach ( cls:AllActorClasses ) { let type = (class)(cls); if ( !type || (type == 'SWWMCollectible') ) continue; let def = GetDefaultByType(type); // check that we can collect it in this IWAD if ( !def.ValidGame() ) continue; let item = Inventory(Spawn(cls)); SWWMCollectible(item).propagated = true; // no score or anims if ( !item.CallTryPickup(self) ) item.Destroy(); } } override void CheatGive( String name, int amount ) { if ( !player.mo || (player.health <= 0) ) return; ingivecheat = true; int giveall = (name~=="everything")?ALL_YESYES:(name~=="all")?ALL_YES:ALL_NO; if ( giveall ) { CheatGive_Health(); CheatGive_Backpack(); CheatGive_Armor(); CheatGive_Keys(); CheatGive_Weapons(); CheatGive_Ammo(); CheatGive_Artifacts(); CheatGive_PuzzlePieces(); if ( giveall == ALL_YESYES ) CheatGive_Collectibles(); } else if ( name ~== "health" ) CheatGive_Health(amount); else if ( name ~== "backpack" ) CheatGive_Backpack(); else if ( name ~== "ammo" ) CheatGive_Ammo(); else if ( name ~== "armor" ) CheatGive_Armor(); else if ( name ~== "keys" ) CheatGive_Keys(); else if ( name ~== "weapons" ) CheatGive_Weapons(); else if ( name ~== "artifacts" ) CheatGive_Artifacts(amount); else if ( name ~== "puzzlepieces" ) CheatGive_PuzzlePieces(amount); else if ( name ~== "collectibles" ) CheatGive_Collectibles(); else { Class type = name; if ( !type || type.IsAbstract() ) { if ( CheckLocalView() ) Console.Printf("'%s' is not a valid inventory item",name); ingivecheat = false; return; } GiveInventory(type,amount,true); } ingivecheat = false; } void CheatTake_Health( int amount = 0 ) { if ( amount >= health ) { CheatSuicide(); if ( player == players[consoleplayer] ) Console.HideConsole(); return; } player.health = health -= amount; } void CheatTake_Backpack() { Inventory i = inv; while ( i ) { let next = i.inv; if ( (i is 'HammerspaceEmbiggener') || (i is 'BackpackItem') ) i.DepleteOrDestroy(); i = next; } } void CheatTake_Ammo() { for ( Inventory i=inv; i; i=i.inv ) { if ( (i is 'Ammo') || (i is 'MagAmmo') ) i.Amount = 0; } } void CheatTake_Armor() { Inventory i = inv; while ( i ) { let next = i.inv; // avoid unclearable (internal) or nodrain (powerup) armors if ( ((i is 'SWWMArmor') && !i.bUNCLEARABLE && !(SWWMArmor(i).bNODRAIN)) || (i is 'SWWMSpareArmor') ) i.DepleteOrDestroy(); i = next; } } void CheatTake_Keys() { Inventory i = inv; while ( i ) { let next = i.inv; if ( i is 'Key' ) i.DepleteOrDestroy(); i = next; } } void CheatTake_Weapons() { Inventory i = inv; while ( i ) { let next = i.inv; // don't take away gestures if ( (i is 'Weapon') && !(i is 'SWWMGesture') && !(i is 'SWWMItemGesture') ) i.DepleteOrDestroy(); i = next; } } void CheatTake_Artifacts() { Inventory i = inv; while ( i ) { let next = i.inv; if ( i.bINVBAR && i.Icon.isValid() && !(i is 'PuzzleItem') ) i.DepleteOrDestroy(); i = next; } } void CheatTake_PuzzlePieces() { Inventory i = inv; while ( i ) { let next = i.inv; if ( i is 'PuzzleItem' ) i.DepleteOrDestroy(); i = next; } } void CheatTake_Collectibles() { Inventory i = inv; while ( i ) { let next = i.inv; if ( i is 'SWWMCollectible' ) i.DepleteOrDestroy(); i = next; } if ( mystats ) mystats.ownedcollectibles.Clear(); } void CheatTake_Item( Class type, int amount = 0 ) { Inventory i = inv; while ( i ) { let next = i.inv; if ( i is type ) { i.Amount -= max(amount,1); if ( i.Amount <= 0 ) { if ( (i is 'SWWMCollectible') && mystats ) { // remove from obtained list let idx = mystats.ownedcollectibles.Find(SWWMCollectible(i).GetClass()); if ( idx < mystats.ownedcollectibles.Size() ) mystats.ownedcollectibles.Delete(idx); } i.DepleteOrDestroy(); } } i = next; } } override void CheatTake( String name, int amount ) { if ( !player.mo || (player.health <= 0) ) return; int takeall = (name~=="everything")?ALL_YESYES:(name~=="all")?ALL_YES:ALL_NO; if ( takeall ) { CheatTake_Ammo(); CheatTake_Backpack(); CheatTake_Armor(); CheatTake_Keys(); CheatTake_Weapons(); CheatTake_Artifacts(); CheatTake_PuzzlePieces(); if ( takeall == ALL_YESYES ) CheatTake_Collectibles(); } else if ( name ~== "health" ) CheatTake_Health(amount); else if ( name ~== "backpack" ) CheatTake_Backpack(); else if ( name ~== "ammo" ) CheatTake_Ammo(); else if ( name ~== "armor" ) CheatTake_Armor(); else if ( name ~== "keys" ) CheatTake_Keys(); else if ( name ~== "weapons" ) CheatTake_Weapons(); else if ( name ~== "artifacts" ) CheatTake_Artifacts(); else if ( name ~== "puzzlepieces" ) CheatTake_PuzzlePieces(); else if ( name ~== "collectibles" ) CheatTake_Collectibles(); else { Class type = name; if ( !type || type.IsAbstract() ) { if ( CheckLocalView() ) Console.Printf("'%s' is not a valid inventory item",name); return; } CheatTake_Item(type,amount); } } }