text: 
  
  --1_0_MK2_CT_Capsules
  USE [perpetuumsa]
  GO
  
  -----------------RE-INTRODUCE MK2 CTs and BOTs-------------------
  --Renable all Mk2 CT's and Mk2 robots
  UPDATE entitydefaults SET enabled=1, hidden=0
  WHERE categoryflags=(SELECT TOP 1 value FROM categoryFlags WHERE name='cf_dynamic_cprg');
  
  UPDATE entitydefaults SET enabled=1, hidden=0, purchasable=1
  WHERE definitionname like '%mk2_bot' and tierlevel=2 and tiertype=1;
  -----------------------------------------------------------------
  
  
  --------------------CREATE MK2 CT CAPSULES-----------------------
  --Creates new EntityDefaults and a new Table relating 2 EntityDefaults
  --The "Definition" in [calibrationtemplateitems] is the new CT "capsule"
  --The "TargetDefinition" is the MK2 CT template item itself
  
  USE [perpetuumsa]
  GO
  
  DROP TABLE IF EXISTS #TEMP
  --Create table to build new EntityDefault entries
  CREATE TABLE #TEMP  
  (targetdefinition int, 
  definitionname varchar(100), 
  quantity int,
  attributeflags bigint,
  categoryflags bigint,
  options varchar(max),
  note nvarchar(2048),
  enabled bit,
  volume float,
  mass float,
  hidden bit,
  health float,
  descriptiontoken nvarchar(100),
  purchasable bit,
  tiertype int,
  tierlevel int)
  INSERT INTO #TEMP 
  SELECT definition, definitionname, 1, 2052, 1179, '', '',1, 0.1, 0.1, 0, 100, '', 1, 1, 2 FROM entitydefaults where definition in (SELECT definition from dynamiccalibrationtemplates)
  
  --Set fields as necesary
  UPDATE #TEMP SET
  definitionname = REPLACE(definitionname,'_dynamic_cprg','_CT_capsule'),
  quantity = 1,
  attributeflags=2052,
  categoryflags = 1179,
  options = '',
  note = 'MK2 CT Capsule!',
  enabled= 1,
  volume = 0.1,
  mass = 0.1,
  hidden = 0,
  health = 100,
  descriptiontoken ='calibration_program_desc',
  purchasable = 1,
  tierlevel = CASE 
  WHEN definitionname like '%_mk2_A_%' THEN 1
  WHEN definitionname like '%_mk2_B_%' THEN 2
  WHEN definitionname like '%_mk2_C_%' THEN 3 
  ELSE 0 END;
  
  
  --Insert the mk2 CT "capsule" definitions
  INSERT INTO entitydefaults 
  	([definitionname]
  	,[quantity]
  	,[attributeflags]
  	,[categoryflags]
  	,[options]
  	,[note]
  	,[enabled]
  	,[volume]
  	,[mass]
  	,[hidden]
  	,[health]
  	,[descriptiontoken]
  	,[purchasable]
  	,[tiertype]
  	,[tierlevel])
  SELECT 
  	[definitionname]
  	,[quantity]
  	,[attributeflags]
  	,[categoryflags]
  	,[options]
  	,[note]
  	,[enabled]
  	,[volume]
  	,[mass]
  	,[hidden]
  	,[health]
  	,[descriptiontoken]
  	,[purchasable]
  	,[tiertype]
  	,[tierlevel]
  FROM #TEMP
  
  --Create a new table in perpetuumsa DB to link the new Capsule definition to the target definition (the mk2 CT)
  DROP TABLE IF EXISTS [perpetuumsa].[dbo].[calibrationtemplateitems];
  
  CREATE TABLE [perpetuumsa].[dbo].[calibrationtemplateitems]
  (definition int, targetdefinition int);
  
  --Insert the relations
  INSERT INTO [perpetuumsa].[dbo].[calibrationtemplateitems]
  (definition, targetdefinition)
  SELECT entitydefaults.definition, #TEMP.targetdefinition FROM #TEMP 
  join entitydefaults on #TEMP.definitionname = entitydefaults.definitionname;
  
  
  DROP TABLE IF EXISTS #TEMP
  
  GO
  
  --------------Part 2 -----------------
  --Reinsert all artifacts (from vanilla data backup)
  --Swap all artifact CT loot to CT-Capsules
  USE [perpetuumsa]
  GO
  
  --MK2 artifact re-insertion and transform to CT capsules
  
  --REINSERT RAW MK2 CT LOOTS (this is a direct copy from vanilla tables -- excuse the definition and type ids)
  INSERT INTO [dbo].[artifactloot]
             ([artifacttype],[definition],[minquantity],[maxquantity],[chance],[packed])
  VALUES
  (5,3054,1,1,1,0.0025),
  (5,3062,1,1,1,0.0025),
  (5,3065,1,1,1,0.0025),
  (5,3068,1,1,1,0.0025),
  (5,3077,1,1,1,0.0025),
  (5,3086,1,1,1,0.0025),
  (5,3089,1,1,1,0.0025),
  (5,3098,1,1,1,0.0025),
  (5,3101,1,1,1,0.0025),
  (5,3104,1,1,1,0.0025),
  (5,3119,1,1,1,0.0025),
  (5,3122,1,1,1,0.0025),
  (5,3125,1,1,1,0.0025),
  (5,3128,1,1,1,0.0025),
  (10,3054,1,1,1,0.005),
  (10,3062,1,1,1,0.005),
  (10,3065,1,1,1,0.005),
  (10,3068,1,1,1,0.005),
  (10,3077,1,1,1,0.005),
  (10,3086,1,1,1,0.005),
  (10,3089,1,1,1,0.005),
  (10,3098,1,1,1,0.005),
  (10,3101,1,1,1,0.005),
  (10,3104,1,1,1,0.005),
  (10,3119,1,1,1,0.005),
  (10,3122,1,1,1,0.005),
  (10,3125,1,1,1,0.005),
  (10,3128,1,1,1,0.005),
  (10,3008,1,1,1,0.0025),
  (10,3063,1,1,1,0.0025),
  (10,3066,1,1,1,0.0025),
  (10,3069,1,1,1,0.0025),
  (10,3078,1,1,1,0.0025),
  (10,3087,1,1,1,0.0025),
  (10,3090,1,1,1,0.0025),
  (10,3099,1,1,1,0.0025),
  (10,3102,1,1,1,0.0025),
  (10,3105,1,1,1,0.0025),
  (10,3120,1,1,1,0.0025),
  (10,3123,1,1,1,0.0025),
  (10,3126,1,1,1,0.0025),
  (10,3129,1,1,1,0.0025),
  (15,3054,1,1,1,0.0075),
  (15,3008,1,1,1,0.005),
  (15,3055,1,1,1,0.0025),
  (15,3062,1,1,1,0.0075),
  (15,3063,1,1,1,0.005),
  (15,3064,1,1,1,0.0025),
  (15,3065,1,1,1,0.0075),
  (15,3066,1,1,1,0.005),
  (15,3067,1,1,1,0.0025),
  (15,3068,1,1,1,0.0075),
  (15,3069,1,1,1,0.005),
  (15,3070,1,1,1,0.0025),
  (15,3077,1,1,1,0.0075),
  (15,3078,1,1,1,0.005),
  (15,3079,1,1,1,0.0025),
  (15,3086,1,1,1,0.0075),
  (15,3087,1,1,1,0.005),
  (15,3088,1,1,1,0.0025),
  (15,3087,1,1,1,0.005),
  (15,3088,1,1,1,0.0025),
  (15,3089,1,1,1,0.0075),
  (15,3090,1,1,1,0.005),
  (15,3091,1,1,1,0.0025),
  (15,3098,1,1,1,0.0075),
  (15,3099,1,1,1,0.005),
  (15,3100,1,1,1,0.0025),
  (15,3101,1,1,1,0.0075),
  (15,3102,1,1,1,0.005),
  (15,3103,1,1,1,0.0025),
  (15,3104,1,1,1,0.0075),
  (15,3105,1,1,1,0.005),
  (15,3106,1,1,1,0.0025),
  (15,3119,1,1,1,0.0075),
  (15,3120,1,1,1,0.005),
  (15,3121,1,1,1,0.0025),
  (15,3122,1,1,1,0.0075),
  (15,3123,1,1,1,0.005),
  (15,3124,1,1,1,0.0025),
  (15,3125,1,1,1,0.0075),
  (15,3126,1,1,1,0.005),
  (15,3127,1,1,1,0.0025),
  (15,3128,1,1,1,0.0075),
  (15,3129,1,1,1,0.005),
  (15,3130,1,1,1,0.0025),
  (34,3056,1,1,1,0.0025),
  (34,3065,1,1,1,0.0025),
  (34,3068,1,1,1,0.0025),
  (34,3071,1,1,1,0.0025),
  (34,3080,1,1,1,0.0025),
  (34,3089,1,1,1,0.0025),
  (34,3092,1,1,1,0.0025),
  (34,3101,1,1,1,0.0025),
  (34,3104,1,1,1,0.0025),
  (34,3107,1,1,1,0.0025),
  (34,3113,1,1,1,0.0025),
  (34,3122,1,1,1,0.0025),
  (34,3125,1,1,1,0.0025),
  (34,3128,1,1,1,0.0025),
  (39,3056,1,1,1,0.005),
  (39,3065,1,1,1,0.005),
  (39,3068,1,1,1,0.005),
  (39,3071,1,1,1,0.005),
  (39,3080,1,1,1,0.005),
  (39,3089,1,1,1,0.005),
  (39,3092,1,1,1,0.005),
  (39,3101,1,1,1,0.005),
  (39,3104,1,1,1,0.005),
  (39,3107,1,1,1,0.005),
  (39,3113,1,1,1,0.005),
  (39,3122,1,1,1,0.005),
  (39,3125,1,1,1,0.005),
  (39,3128,1,1,1,0.005),
  (39,3057,1,1,1,0.0025),
  (39,3066,1,1,1,0.0025),
  (39,3068,1,1,1,0.0025),
  (39,3072,1,1,1,0.0025),
  (39,3081,1,1,1,0.0025),
  (39,3090,1,1,1,0.0025),
  (39,3093,1,1,1,0.0025),
  (39,3102,1,1,1,0.0025),
  (39,3105,1,1,1,0.0025),
  (39,3108,1,1,1,0.0025),
  (39,3114,1,1,1,0.0025),
  (39,3123,1,1,1,0.0025),
  (39,3126,1,1,1,0.0025),
  (39,3129,1,1,1,0.0025),
  (44,3056,1,1,1,0.0075),
  (44,3057,1,1,1,0.005),
  (44,3058,1,1,1,0.0025),
  (44,3065,1,1,1,0.0075),
  (44,3067,1,1,1,0.0025),
  (44,3068,1,1,1,0.0075),
  (44,3069,1,1,1,0.005),
  (44,3070,1,1,1,0.0025),
  (44,3071,1,1,1,0.0075),
  (44,3072,1,1,1,0.005),
  (44,3073,1,1,1,0.0025),
  (44,3080,1,1,1,0.0075),
  (44,3081,1,1,1,0.005),
  (44,3082,1,1,1,0.0025),
  (44,3089,1,1,1,0.0075),
  (44,3090,1,1,1,0.005),
  (44,3091,1,1,1,0.0025),
  (44,3092,1,1,1,0.0075),
  (44,3093,1,1,1,0.005),
  (44,3094,1,1,1,0.0025),
  (44,3101,1,1,1,0.0075),
  (44,3102,1,1,1,0.005),
  (44,3103,1,1,1,0.0025),
  (44,3104,1,1,1,0.0075),
  (44,3105,1,1,1,0.005),
  (44,3106,1,1,1,0.0025),
  (44,3107,1,1,1,0.0075),
  (44,3108,1,1,1,0.005),
  (44,3109,1,1,1,0.0025),
  (44,3113,1,1,1,0.0075),
  (44,3114,1,1,1,0.005),
  (44,3115,1,1,1,0.0025),
  (44,3122,1,1,1,0.0075),
  (44,3123,1,1,1,0.005),
  (44,3124,1,1,1,0.0025),
  (44,3125,1,1,1,0.0075),
  (44,3126,1,1,1,0.005),
  (44,3127,1,1,1,0.0025),
  (44,3128,1,1,1,0.0075),
  (44,3129,1,1,1,0.005),
  (44,3130,1,1,1,0.0025),
  (64,3059,1,1,1,0.0025),
  (64,3065,1,1,1,0.0025),
  (64,3068,1,1,1,0.0025),
  (64,3074,1,1,1,0.0025),
  (64,3083,1,1,1,0.0025),
  (64,3089,1,1,1,0.0025),
  (64,3095,1,1,1,0.0025),
  (64,3101,1,1,1,0.0025),
  (64,3104,1,1,1,0.0025),
  (64,3110,1,1,1,0.0025),
  (64,3116,1,1,1,0.0025),
  (64,3122,1,1,1,0.0025),
  (64,3125,1,1,1,0.0025),
  (64,3128,1,1,1,0.0025),
  (69,3059,1,1,1,0.005),
  (69,3065,1,1,1,0.005),
  (69,3068,1,1,1,0.005),
  (69,3074,1,1,1,0.005),
  (69,3083,1,1,1,0.005),
  (69,3089,1,1,1,0.005),
  (69,3095,1,1,1,0.005),
  (69,3101,1,1,1,0.005),
  (69,3104,1,1,1,0.005),
  (69,3110,1,1,1,0.005),
  (69,3116,1,1,1,0.005),
  (69,3122,1,1,1,0.005),
  (69,3125,1,1,1,0.005),
  (69,3128,1,1,1,0.005),
  (69,3060,1,1,1,0.0025),
  (69,3066,1,1,1,0.0025),
  (69,3069,1,1,1,0.0025),
  (69,3075,1,1,1,0.0025),
  (69,3084,1,1,1,0.0025),
  (69,3090,1,1,1,0.0025),
  (69,3096,1,1,1,0.0025),
  (69,3102,1,1,1,0.0025),
  (69,3105,1,1,1,0.0025),
  (69,3111,1,1,1,0.0025),
  (69,3117,1,1,1,0.0025),
  (69,3123,1,1,1,0.0025),
  (69,3126,1,1,1,0.0025),
  (69,3129,1,1,1,0.0025),
  (74,3059,1,1,1,0.0075),
  (74,3065,1,1,1,0.0075),
  (74,3068,1,1,1,0.0075),
  (74,3074,1,1,1,0.0075),
  (74,3083,1,1,1,0.0075),
  (74,3089,1,1,1,0.0075),
  (74,3095,1,1,1,0.0075),
  (74,3101,1,1,1,0.0075),
  (74,3104,1,1,1,0.0075),
  (74,3110,1,1,1,0.0075),
  (74,3116,1,1,1,0.0075),
  (74,3122,1,1,1,0.0075),
  (74,3125,1,1,1,0.0075),
  (74,3128,1,1,1,0.0075),
  (74,3060,1,1,1,0.005),
  (74,3066,1,1,1,0.005),
  (74,3069,1,1,1,0.005),
  (74,3075,1,1,1,0.005),
  (74,3084,1,1,1,0.005),
  (74,3090,1,1,1,0.005),
  (74,3096,1,1,1,0.005),
  (74,3102,1,1,1,0.005),
  (74,3105,1,1,1,0.005),
  (74,3111,1,1,1,0.005),
  (74,3117,1,1,1,0.005),
  (74,3123,1,1,1,0.005),
  (74,3126,1,1,1,0.005),
  (74,3129,1,1,1,0.005),
  (74,3061,1,1,1,0.0025),
  (74,3067,1,1,1,0.0025),
  (74,3070,1,1,1,0.0025),
  (74,3076,1,1,1,0.0025),
  (74,3085,1,1,1,0.0025),
  (74,3091,1,1,1,0.0025),
  (74,3097,1,1,1,0.0025),
  (74,3103,1,1,1,0.0025),
  (74,3106,1,1,1,0.0025),
  (74,3112,1,1,1,0.0025),
  (74,3118,1,1,1,0.0025),
  (74,3124,1,1,1,0.0025),
  (74,3127,1,1,1,0.0025),
  (74,3130,1,1,1,0.0025),
  (30,3100,1,1,1,0.005),
  (30,3103,1,1,1,0.005),
  (30,3106,1,1,1,0.005),
  (30,3121,1,1,1,0.005),
  (30,3124,1,1,1,0.005),
  (30,3127,1,1,1,0.005),
  (30,3130,1,1,1,0.005),
  (20,3008,1,1,1,0.005),
  (20,3063,1,1,1,0.005),
  (20,3066,1,1,1,0.005),
  (20,3069,1,1,1,0.005),
  (20,3078,1,1,1,0.005),
  (20,3087,1,1,1,0.005),
  (20,3090,1,1,1,0.005),
  (20,3099,1,1,1,0.005),
  (20,3102,1,1,1,0.005),
  (20,3105,1,1,1,0.005),
  (20,3120,1,1,1,0.005),
  (20,3123,1,1,1,0.005),
  (20,3126,1,1,1,0.005),
  (20,3129,1,1,1,0.005),
  (25,3008,1,1,1,0.01),
  (25,3063,1,1,1,0.01),
  (25,3066,1,1,1,0.01),
  (25,3069,1,1,1,0.01),
  (25,3078,1,1,1,0.01),
  (25,3087,1,1,1,0.01),
  (25,3090,1,1,1,0.01),
  (25,3099,1,1,1,0.01),
  (25,3102,1,1,1,0.01),
  (25,3105,1,1,1,0.01),
  (25,3120,1,1,1,0.01),
  (25,3123,1,1,1,0.01),
  (25,3126,1,1,1,0.01),
  (25,3129,1,1,1,0.01),
  (25,3055,1,1,1,0.0025),
  (25,3064,1,1,1,0.0025),
  (25,3067,1,1,1,0.0025),
  (25,3070,1,1,1,0.0025),
  (25,3079,1,1,1,0.0025),
  (25,3088,1,1,1,0.0025),
  (25,3091,1,1,1,0.0025),
  (25,3100,1,1,1,0.0025),
  (25,3103,1,1,1,0.0025),
  (25,3106,1,1,1,0.0025),
  (25,3121,1,1,1,0.0025),
  (25,3124,1,1,1,0.0025),
  (25,3127,1,1,1,0.0025),
  (25,3130,1,1,1,0.0025),
  (30,3055,1,1,1,0.005),
  (30,3064,1,1,1,0.005),
  (30,3067,1,1,1,0.005),
  (30,3070,1,1,1,0.005),
  (30,3079,1,1,1,0.005),
  (30,3088,1,1,1,0.005),
  (30,3088,1,1,1,0.005),
  (30,3091,1,1,1,0.005),
  (48,3072,1,1,1,0.005),
  (54,3057,1,1,1,0.01),
  (54,3066,1,1,1,0.01),
  (54,3069,1,1,1,0.01),
  (54,3072,1,1,1,0.01),
  (54,3081,1,1,1,0.01),
  (54,3090,1,1,1,0.01),
  (54,3093,1,1,1,0.01),
  (54,3102,1,1,1,0.01),
  (54,3105,1,1,1,0.01),
  (54,3108,1,1,1,0.01),
  (54,3114,1,1,1,0.01),
  (54,3123,1,1,1,0.01),
  (59,3070,1,1,1,0.005),
  (59,3073,1,1,1,0.005),
  (59,3082,1,1,1,0.005),
  (59,3091,1,1,1,0.005),
  (59,3094,1,1,1,0.005),
  (59,3103,1,1,1,0.005),
  (59,3115,1,1,1,0.005),
  (59,3124,1,1,1,0.005),
  (59,3127,1,1,1,0.005),
  (59,3130,1,1,1,0.005),
  (79,3060,1,1,1,0.005),
  (79,3066,1,1,1,0.005),
  (79,3069,1,1,1,0.005),
  (79,3075,1,1,1,0.005),
  (79,3084,1,1,1,0.005),
  (79,3090,1,1,1,0.005),
  (79,3111,1,1,1,0.005),
  (79,3117,1,1,1,0.005),
  (79,3123,1,1,1,0.005),
  (79,3126,1,1,1,0.005),
  (79,3129,1,1,1,0.005),
  (84,3105,1,1,1,0.01),
  (84,3111,1,1,1,0.01),
  (84,3117,1,1,1,0.01),
  (84,3123,1,1,1,0.01),
  (84,3126,1,1,1,0.01),
  (84,3129,1,1,1,0.01),
  (84,3085,1,1,1,0.0025),
  (84,3091,1,1,1,0.0025),
  (84,3097,1,1,1,0.0025),
  (84,3103,1,1,1,0.0025),
  (84,3106,1,1,1,0.0025),
  (84,3112,1,1,1,0.0025),
  (89,3070,1,1,1,0.005),
  (89,3076,1,1,1,0.005),
  (89,3085,1,1,1,0.005),
  (89,3091,1,1,1,0.005),
  (89,3097,1,1,1,0.005),
  (89,3103,1,1,1,0.005),
  (89,3106,1,1,1,0.005),
  (89,3112,1,1,1,0.005),
  (89,3118,1,1,1,0.005),
  (89,3124,1,1,1,0.005),
  (48,3057,1,1,1,0.005),
  (48,3066,1,1,1,0.005),
  (48,3069,1,1,1,0.005),
  (48,3081,1,1,1,0.005),
  (48,3090,1,1,1,0.005),
  (48,3093,1,1,1,0.005),
  (48,3102,1,1,1,0.005),
  (48,3105,1,1,1,0.005),
  (48,3108,1,1,1,0.005),
  (48,3114,1,1,1,0.005),
  (48,3123,1,1,1,0.005),
  (48,3126,1,1,1,0.005),
  (48,3129,1,1,1,0.005),
  (54,3126,1,1,1,0.01),
  (54,3129,1,1,1,0.01),
  (79,3096,1,1,1,0.005),
  (79,3102,1,1,1,0.005),
  (79,3105,1,1,1,0.005),
  (84,3060,1,1,1,0.01),
  (84,3066,1,1,1,0.01),
  (84,3069,1,1,1,0.01),
  (84,3075,1,1,1,0.01),
  (84,3084,1,1,1,0.01),
  (84,3090,1,1,1,0.01),
  (84,3096,1,1,1,0.01),
  (89,3127,1,1,1,0.005),
  (89,3130,1,1,1,0.005),
  (54,3058,1,1,1,0.0025),
  (54,3067,1,1,1,0.0025),
  (54,3069,1,1,1,0.01),
  (54,3073,1,1,1,0.0025),
  (54,3082,1,1,1,0.0025),
  (54,3091,1,1,1,0.0025),
  (54,3094,1,1,1,0.0025),
  (54,3103,1,1,1,0.0025),
  (54,3106,1,1,1,0.0025),
  (54,3109,1,1,1,0.0025),
  (54,3115,1,1,1,0.0025),
  (54,3124,1,1,1,0.0025),
  (54,3127,1,1,1,0.0025),
  (54,3130,1,1,1,0.0025),
  (59,3058,1,1,1,0.005),
  (59,3067,1,1,1,0.005),
  (59,3106,1,1,1,0.005),
  (59,3109,1,1,1,0.005),
  (84,3102,1,1,1,0.01),
  (84,3061,1,1,1,0.0025),
  (84,3067,1,1,1,0.0025),
  (84,3070,1,1,1,0.0025),
  (84,3076,1,1,1,0.0025),
  (84,3118,1,1,1,0.0025),
  (84,3124,1,1,1,0.0025),
  (84,3127,1,1,1,0.0025),
  (84,3130,1,1,1,0.0025),
  (89,3061,1,1,1,0.005),
  (89,3067,1,1,1,0.005),
  (247,3072,1,1,1,0.005),
  (247,3057,1,1,1,0.005),
  (247,3066,1,1,1,0.005),
  (247,3069,1,1,1,0.005),
  (247,3081,1,1,1,0.005),
  (247,3090,1,1,1,0.005),
  (247,3093,1,1,1,0.005),
  (247,3102,1,1,1,0.005),
  (247,3105,1,1,1,0.005),
  (247,3108,1,1,1,0.005),
  (247,3114,1,1,1,0.005),
  (247,3123,1,1,1,0.005),
  (247,3126,1,1,1,0.005),
  (247,3129,1,1,1,0.005),
  (247,5003,1,1,1,0.005),
  (248,3057,1,1,1,0.01),
  (248,3066,1,1,1,0.01),
  (248,3069,1,1,1,0.01),
  (248,3072,1,1,1,0.01),
  (248,3081,1,1,1,0.01),
  (248,3090,1,1,1,0.01),
  (248,3093,1,1,1,0.01),
  (248,3102,1,1,1,0.01),
  (248,3105,1,1,1,0.01),
  (248,3108,1,1,1,0.01),
  (248,3114,1,1,1,0.01),
  (248,3123,1,1,1,0.01),
  (248,3126,1,1,1,0.01),
  (248,3129,1,1,1,0.01),
  (248,3058,1,1,1,0.0025),
  (248,3067,1,1,1,0.0025),
  (248,3069,1,1,1,0.01),
  (248,3073,1,1,1,0.0025),
  (248,3082,1,1,1,0.0025),
  (248,3091,1,1,1,0.0025),
  (248,3094,1,1,1,0.0025),
  (248,3103,1,1,1,0.0025),
  (248,3106,1,1,1,0.0025),
  (248,3109,1,1,1,0.0025),
  (248,3115,1,1,1,0.0025),
  (248,3124,1,1,1,0.0025),
  (248,3127,1,1,1,0.0025),
  (248,3130,1,1,1,0.0025),
  (248,5003,1,1,1,0.01),
  (248,5004,1,1,1,0.0025),
  (249,3070,1,1,1,0.005),
  (249,3073,1,1,1,0.005),
  (249,3082,1,1,1,0.005),
  (249,3091,1,1,1,0.005),
  (249,3094,1,1,1,0.005),
  (249,3103,1,1,1,0.005),
  (249,3115,1,1,1,0.005),
  (249,3124,1,1,1,0.005),
  (249,3127,1,1,1,0.005),
  (249,3130,1,1,1,0.005),
  (249,3058,1,1,1,0.005),
  (249,3067,1,1,1,0.005),
  (249,3106,1,1,1,0.005),
  (249,3109,1,1,1,0.005),
  (249,5004,1,1,1,0.005),
  (250,3008,1,1,1,0.005),
  (250,3063,1,1,1,0.005),
  (250,3066,1,1,1,0.005),
  (250,3069,1,1,1,0.005),
  (250,3078,1,1,1,0.005),
  (250,3087,1,1,1,0.005),
  (250,3090,1,1,1,0.005),
  (250,3099,1,1,1,0.005),
  (250,3102,1,1,1,0.005),
  (250,3105,1,1,1,0.005),
  (250,3120,1,1,1,0.005),
  (250,3123,1,1,1,0.005),
  (250,3126,1,1,1,0.005),
  (250,3129,1,1,1,0.005),
  (250,5003,1,1,1,0.005),
  (251,3008,1,1,1,0.01),
  (251,3063,1,1,1,0.01),
  (251,3066,1,1,1,0.01),
  (251,3069,1,1,1,0.01),
  (251,3078,1,1,1,0.01),
  (251,3087,1,1,1,0.01),
  (251,3090,1,1,1,0.01),
  (251,3099,1,1,1,0.01),
  (251,3102,1,1,1,0.01),
  (251,3105,1,1,1,0.01),
  (251,3120,1,1,1,0.01),
  (251,3123,1,1,1,0.01),
  (251,3126,1,1,1,0.01),
  (251,3129,1,1,1,0.01),
  (251,3055,1,1,1,0.0025),
  (251,3064,1,1,1,0.0025),
  (251,3067,1,1,1,0.0025),
  (251,3070,1,1,1,0.0025),
  (251,3079,1,1,1,0.0025),
  (251,3088,1,1,1,0.0025),
  (251,3091,1,1,1,0.0025),
  (251,3100,1,1,1,0.0025),
  (251,3103,1,1,1,0.0025),
  (251,3106,1,1,1,0.0025),
  (251,3121,1,1,1,0.0025),
  (251,3124,1,1,1,0.0025),
  (251,3127,1,1,1,0.0025),
  (251,3130,1,1,1,0.0025),
  (251,5003,1,1,1,0.01),
  (251,5004,1,1,1,0.0025),
  (252,3100,1,1,1,0.005),
  (252,3103,1,1,1,0.005),
  (252,3106,1,1,1,0.005),
  (252,3121,1,1,1,0.005),
  (252,3124,1,1,1,0.005),
  (252,3127,1,1,1,0.005),
  (252,3130,1,1,1,0.005),
  (252,3055,1,1,1,0.005),
  (252,3064,1,1,1,0.005),
  (252,3067,1,1,1,0.005),
  (252,3070,1,1,1,0.005),
  (252,3079,1,1,1,0.005),
  (252,3088,1,1,1,0.005),
  (252,3088,1,1,1,0.005),
  (252,3091,1,1,1,0.005),
  (252,5004,1,1,1,0.005),
  (253,3060,1,1,1,0.005),
  (253,3066,1,1,1,0.005),
  (253,3069,1,1,1,0.005),
  (253,3075,1,1,1,0.005),
  (253,3084,1,1,1,0.005),
  (253,3090,1,1,1,0.005),
  (253,3111,1,1,1,0.005),
  (253,3117,1,1,1,0.005),
  (253,3123,1,1,1,0.005),
  (253,3126,1,1,1,0.005),
  (253,3129,1,1,1,0.005),
  (253,3096,1,1,1,0.005),
  (253,3102,1,1,1,0.005),
  (253,3105,1,1,1,0.005),
  (253,5003,1,1,1,0.005),
  (254,3105,1,1,1,0.01),
  (254,3111,1,1,1,0.01),
  (254,3117,1,1,1,0.01),
  (254,3123,1,1,1,0.01),
  (254,3126,1,1,1,0.01),
  (254,3129,1,1,1,0.01),
  (254,3085,1,1,1,0.0025),
  (254,3091,1,1,1,0.0025),
  (254,3097,1,1,1,0.0025),
  (254,3103,1,1,1,0.0025),
  (254,3106,1,1,1,0.0025),
  (254,3112,1,1,1,0.0025),
  (254,3060,1,1,1,0.01),
  (254,3066,1,1,1,0.01),
  (254,3069,1,1,1,0.01),
  (254,3075,1,1,1,0.01),
  (254,3084,1,1,1,0.01),
  (254,3090,1,1,1,0.01),
  (254,3096,1,1,1,0.01),
  (254,3102,1,1,1,0.01),
  (254,3061,1,1,1,0.0025),
  (254,3067,1,1,1,0.0025),
  (254,3070,1,1,1,0.0025),
  (254,3076,1,1,1,0.0025),
  (254,3118,1,1,1,0.0025),
  (254,3124,1,1,1,0.0025),
  (254,3127,1,1,1,0.0025),
  (254,3130,1,1,1,0.0025),
  (254,5003,1,1,1,0.01),
  (254,5004,1,1,1,0.0025),
  (255,3070,1,1,1,0.005),
  (255,3076,1,1,1,0.005),
  (255,3085,1,1,1,0.005),
  (255,3091,1,1,1,0.005),
  (255,3097,1,1,1,0.005),
  (255,3103,1,1,1,0.005),
  (255,3106,1,1,1,0.005),
  (255,3112,1,1,1,0.005),
  (255,3118,1,1,1,0.005),
  (255,3124,1,1,1,0.005),
  (255,3127,1,1,1,0.005),
  (255,3130,1,1,1,0.005),
  (255,3061,1,1,1,0.005),
  (255,3067,1,1,1,0.005),
  (255,5004,1,1,1,0.005);
  
  GO
  
  
  --Set all the mk2 CT loot to mk2 CT-capsules
  UPDATE artifactloot
  SET
  definition = (SELECT TOP 1 calibrationtemplateitems.definition FROM calibrationtemplateitems WHERE calibrationtemplateitems.targetdefinition=artifactloot.definition)
  WHERE definition in (SELECT definition FROM entitydefaults where categoryflags=(SELECT TOP 1 value FROM categoryFlags WHERE name='cf_dynamic_cprg'));
  
  GO
  
  
  
  --1_1_MK2_CT_Capsules_artiloot_fix
  USE [perpetuumsa]
  GO
  
  ------ARTIFACT LOOT CORRECTIONS AND CHANCE UPDATE
  --First: properly recover the 'chance' col from raw vanilla data
  --UPDATE: the EXISTING loot with this chance
  --+++++++++++
  --INCLUDES LOOT-CHANCE CHANGE: 50% reduction in chance for all CT-capsules from vanilla chance
  --
  --Notes: This script is stable to re-run arbitrary times after 1_0_MK2_CT_Capsules.sql
  --Due to chance modification from fixed values extracted at vanilla-state
  
  
  DROP TABLE IF EXISTS #TEMP_OLD_MK2CT_LOOTS
  
  --Table of the MK2CT loots, note position of chance column
  CREATE TABLE #TEMP_OLD_MK2CT_LOOTS
  ( 
    [artifacttype] int,
    [definition] int,
    [minquantity] int,
    [maxquantity] int,
    [packed] bit,
    [chance] float
  );
  
  --Insert all recovered MK2 CT loot data from vanilla table -- chance column position to match data
  INSERT INTO #TEMP_OLD_MK2CT_LOOTS ([artifacttype],[definition],[minquantity],[maxquantity],[packed],[chance])
  VALUES
  (5,3054,1,1,1,0.0025),
  (5,3062,1,1,1,0.0025),
  (5,3065,1,1,1,0.0025),
  (5,3068,1,1,1,0.0025),
  (5,3077,1,1,1,0.0025),
  (5,3086,1,1,1,0.0025),
  (5,3089,1,1,1,0.0025),
  (5,3098,1,1,1,0.0025),
  (5,3101,1,1,1,0.0025),
  (5,3104,1,1,1,0.0025),
  (5,3119,1,1,1,0.0025),
  (5,3122,1,1,1,0.0025),
  (5,3125,1,1,1,0.0025),
  (5,3128,1,1,1,0.0025),
  (10,3054,1,1,1,0.005),
  (10,3062,1,1,1,0.005),
  (10,3065,1,1,1,0.005),
  (10,3068,1,1,1,0.005),
  (10,3077,1,1,1,0.005),
  (10,3086,1,1,1,0.005),
  (10,3089,1,1,1,0.005),
  (10,3098,1,1,1,0.005),
  (10,3101,1,1,1,0.005),
  (10,3104,1,1,1,0.005),
  (10,3119,1,1,1,0.005),
  (10,3122,1,1,1,0.005),
  (10,3125,1,1,1,0.005),
  (10,3128,1,1,1,0.005),
  (10,3008,1,1,1,0.0025),
  (10,3063,1,1,1,0.0025),
  (10,3066,1,1,1,0.0025),
  (10,3069,1,1,1,0.0025),
  (10,3078,1,1,1,0.0025),
  (10,3087,1,1,1,0.0025),
  (10,3090,1,1,1,0.0025),
  (10,3099,1,1,1,0.0025),
  (10,3102,1,1,1,0.0025),
  (10,3105,1,1,1,0.0025),
  (10,3120,1,1,1,0.0025),
  (10,3123,1,1,1,0.0025),
  (10,3126,1,1,1,0.0025),
  (10,3129,1,1,1,0.0025),
  (15,3054,1,1,1,0.0075),
  (15,3008,1,1,1,0.005),
  (15,3055,1,1,1,0.0025),
  (15,3062,1,1,1,0.0075),
  (15,3063,1,1,1,0.005),
  (15,3064,1,1,1,0.0025),
  (15,3065,1,1,1,0.0075),
  (15,3066,1,1,1,0.005),
  (15,3067,1,1,1,0.0025),
  (15,3068,1,1,1,0.0075),
  (15,3069,1,1,1,0.005),
  (15,3070,1,1,1,0.0025),
  (15,3077,1,1,1,0.0075),
  (15,3078,1,1,1,0.005),
  (15,3079,1,1,1,0.0025),
  (15,3086,1,1,1,0.0075),
  (15,3087,1,1,1,0.005),
  (15,3088,1,1,1,0.0025),
  (15,3087,1,1,1,0.005),
  (15,3088,1,1,1,0.0025),
  (15,3089,1,1,1,0.0075),
  (15,3090,1,1,1,0.005),
  (15,3091,1,1,1,0.0025),
  (15,3098,1,1,1,0.0075),
  (15,3099,1,1,1,0.005),
  (15,3100,1,1,1,0.0025),
  (15,3101,1,1,1,0.0075),
  (15,3102,1,1,1,0.005),
  (15,3103,1,1,1,0.0025),
  (15,3104,1,1,1,0.0075),
  (15,3105,1,1,1,0.005),
  (15,3106,1,1,1,0.0025),
  (15,3119,1,1,1,0.0075),
  (15,3120,1,1,1,0.005),
  (15,3121,1,1,1,0.0025),
  (15,3122,1,1,1,0.0075),
  (15,3123,1,1,1,0.005),
  (15,3124,1,1,1,0.0025),
  (15,3125,1,1,1,0.0075),
  (15,3126,1,1,1,0.005),
  (15,3127,1,1,1,0.0025),
  (15,3128,1,1,1,0.0075),
  (15,3129,1,1,1,0.005),
  (15,3130,1,1,1,0.0025),
  (34,3056,1,1,1,0.0025),
  (34,3065,1,1,1,0.0025),
  (34,3068,1,1,1,0.0025),
  (34,3071,1,1,1,0.0025),
  (34,3080,1,1,1,0.0025),
  (34,3089,1,1,1,0.0025),
  (34,3092,1,1,1,0.0025),
  (34,3101,1,1,1,0.0025),
  (34,3104,1,1,1,0.0025),
  (34,3107,1,1,1,0.0025),
  (34,3113,1,1,1,0.0025),
  (34,3122,1,1,1,0.0025),
  (34,3125,1,1,1,0.0025),
  (34,3128,1,1,1,0.0025),
  (39,3056,1,1,1,0.005),
  (39,3065,1,1,1,0.005),
  (39,3068,1,1,1,0.005),
  (39,3071,1,1,1,0.005),
  (39,3080,1,1,1,0.005),
  (39,3089,1,1,1,0.005),
  (39,3092,1,1,1,0.005),
  (39,3101,1,1,1,0.005),
  (39,3104,1,1,1,0.005),
  (39,3107,1,1,1,0.005),
  (39,3113,1,1,1,0.005),
  (39,3122,1,1,1,0.005),
  (39,3125,1,1,1,0.005),
  (39,3128,1,1,1,0.005),
  (39,3057,1,1,1,0.0025),
  (39,3066,1,1,1,0.0025),
  (39,3068,1,1,1,0.0025),
  (39,3072,1,1,1,0.0025),
  (39,3081,1,1,1,0.0025),
  (39,3090,1,1,1,0.0025),
  (39,3093,1,1,1,0.0025),
  (39,3102,1,1,1,0.0025),
  (39,3105,1,1,1,0.0025),
  (39,3108,1,1,1,0.0025),
  (39,3114,1,1,1,0.0025),
  (39,3123,1,1,1,0.0025),
  (39,3126,1,1,1,0.0025),
  (39,3129,1,1,1,0.0025),
  (44,3056,1,1,1,0.0075),
  (44,3057,1,1,1,0.005),
  (44,3058,1,1,1,0.0025),
  (44,3065,1,1,1,0.0075),
  (44,3067,1,1,1,0.0025),
  (44,3068,1,1,1,0.0075),
  (44,3069,1,1,1,0.005),
  (44,3070,1,1,1,0.0025),
  (44,3071,1,1,1,0.0075),
  (44,3072,1,1,1,0.005),
  (44,3073,1,1,1,0.0025),
  (44,3080,1,1,1,0.0075),
  (44,3081,1,1,1,0.005),
  (44,3082,1,1,1,0.0025),
  (44,3089,1,1,1,0.0075),
  (44,3090,1,1,1,0.005),
  (44,3091,1,1,1,0.0025),
  (44,3092,1,1,1,0.0075),
  (44,3093,1,1,1,0.005),
  (44,3094,1,1,1,0.0025),
  (44,3101,1,1,1,0.0075),
  (44,3102,1,1,1,0.005),
  (44,3103,1,1,1,0.0025),
  (44,3104,1,1,1,0.0075),
  (44,3105,1,1,1,0.005),
  (44,3106,1,1,1,0.0025),
  (44,3107,1,1,1,0.0075),
  (44,3108,1,1,1,0.005),
  (44,3109,1,1,1,0.0025),
  (44,3113,1,1,1,0.0075),
  (44,3114,1,1,1,0.005),
  (44,3115,1,1,1,0.0025),
  (44,3122,1,1,1,0.0075),
  (44,3123,1,1,1,0.005),
  (44,3124,1,1,1,0.0025),
  (44,3125,1,1,1,0.0075),
  (44,3126,1,1,1,0.005),
  (44,3127,1,1,1,0.0025),
  (44,3128,1,1,1,0.0075),
  (44,3129,1,1,1,0.005),
  (44,3130,1,1,1,0.0025),
  (64,3059,1,1,1,0.0025),
  (64,3065,1,1,1,0.0025),
  (64,3068,1,1,1,0.0025),
  (64,3074,1,1,1,0.0025),
  (64,3083,1,1,1,0.0025),
  (64,3089,1,1,1,0.0025),
  (64,3095,1,1,1,0.0025),
  (64,3101,1,1,1,0.0025),
  (64,3104,1,1,1,0.0025),
  (64,3110,1,1,1,0.0025),
  (64,3116,1,1,1,0.0025),
  (64,3122,1,1,1,0.0025),
  (64,3125,1,1,1,0.0025),
  (64,3128,1,1,1,0.0025),
  (69,3059,1,1,1,0.005),
  (69,3065,1,1,1,0.005),
  (69,3068,1,1,1,0.005),
  (69,3074,1,1,1,0.005),
  (69,3083,1,1,1,0.005),
  (69,3089,1,1,1,0.005),
  (69,3095,1,1,1,0.005),
  (69,3101,1,1,1,0.005),
  (69,3104,1,1,1,0.005),
  (69,3110,1,1,1,0.005),
  (69,3116,1,1,1,0.005),
  (69,3122,1,1,1,0.005),
  (69,3125,1,1,1,0.005),
  (69,3128,1,1,1,0.005),
  (69,3060,1,1,1,0.0025),
  (69,3066,1,1,1,0.0025),
  (69,3069,1,1,1,0.0025),
  (69,3075,1,1,1,0.0025),
  (69,3084,1,1,1,0.0025),
  (69,3090,1,1,1,0.0025),
  (69,3096,1,1,1,0.0025),
  (69,3102,1,1,1,0.0025),
  (69,3105,1,1,1,0.0025),
  (69,3111,1,1,1,0.0025),
  (69,3117,1,1,1,0.0025),
  (69,3123,1,1,1,0.0025),
  (69,3126,1,1,1,0.0025),
  (69,3129,1,1,1,0.0025),
  (74,3059,1,1,1,0.0075),
  (74,3065,1,1,1,0.0075),
  (74,3068,1,1,1,0.0075),
  (74,3074,1,1,1,0.0075),
  (74,3083,1,1,1,0.0075),
  (74,3089,1,1,1,0.0075),
  (74,3095,1,1,1,0.0075),
  (74,3101,1,1,1,0.0075),
  (74,3104,1,1,1,0.0075),
  (74,3110,1,1,1,0.0075),
  (74,3116,1,1,1,0.0075),
  (74,3122,1,1,1,0.0075),
  (74,3125,1,1,1,0.0075),
  (74,3128,1,1,1,0.0075),
  (74,3060,1,1,1,0.005),
  (74,3066,1,1,1,0.005),
  (74,3069,1,1,1,0.005),
  (74,3075,1,1,1,0.005),
  (74,3084,1,1,1,0.005),
  (74,3090,1,1,1,0.005),
  (74,3096,1,1,1,0.005),
  (74,3102,1,1,1,0.005),
  (74,3105,1,1,1,0.005),
  (74,3111,1,1,1,0.005),
  (74,3117,1,1,1,0.005),
  (74,3123,1,1,1,0.005),
  (74,3126,1,1,1,0.005),
  (74,3129,1,1,1,0.005),
  (74,3061,1,1,1,0.0025),
  (74,3067,1,1,1,0.0025),
  (74,3070,1,1,1,0.0025),
  (74,3076,1,1,1,0.0025),
  (74,3085,1,1,1,0.0025),
  (74,3091,1,1,1,0.0025),
  (74,3097,1,1,1,0.0025),
  (74,3103,1,1,1,0.0025),
  (74,3106,1,1,1,0.0025),
  (74,3112,1,1,1,0.0025),
  (74,3118,1,1,1,0.0025),
  (74,3124,1,1,1,0.0025),
  (74,3127,1,1,1,0.0025),
  (74,3130,1,1,1,0.0025),
  (30,3100,1,1,1,0.005),
  (30,3103,1,1,1,0.005),
  (30,3106,1,1,1,0.005),
  (30,3121,1,1,1,0.005),
  (30,3124,1,1,1,0.005),
  (30,3127,1,1,1,0.005),
  (30,3130,1,1,1,0.005),
  (20,3008,1,1,1,0.005),
  (20,3063,1,1,1,0.005),
  (20,3066,1,1,1,0.005),
  (20,3069,1,1,1,0.005),
  (20,3078,1,1,1,0.005),
  (20,3087,1,1,1,0.005),
  (20,3090,1,1,1,0.005),
  (20,3099,1,1,1,0.005),
  (20,3102,1,1,1,0.005),
  (20,3105,1,1,1,0.005),
  (20,3120,1,1,1,0.005),
  (20,3123,1,1,1,0.005),
  (20,3126,1,1,1,0.005),
  (20,3129,1,1,1,0.005),
  (25,3008,1,1,1,0.01),
  (25,3063,1,1,1,0.01),
  (25,3066,1,1,1,0.01),
  (25,3069,1,1,1,0.01),
  (25,3078,1,1,1,0.01),
  (25,3087,1,1,1,0.01),
  (25,3090,1,1,1,0.01),
  (25,3099,1,1,1,0.01),
  (25,3102,1,1,1,0.01),
  (25,3105,1,1,1,0.01),
  (25,3120,1,1,1,0.01),
  (25,3123,1,1,1,0.01),
  (25,3126,1,1,1,0.01),
  (25,3129,1,1,1,0.01),
  (25,3055,1,1,1,0.0025),
  (25,3064,1,1,1,0.0025),
  (25,3067,1,1,1,0.0025),
  (25,3070,1,1,1,0.0025),
  (25,3079,1,1,1,0.0025),
  (25,3088,1,1,1,0.0025),
  (25,3091,1,1,1,0.0025),
  (25,3100,1,1,1,0.0025),
  (25,3103,1,1,1,0.0025),
  (25,3106,1,1,1,0.0025),
  (25,3121,1,1,1,0.0025),
  (25,3124,1,1,1,0.0025),
  (25,3127,1,1,1,0.0025),
  (25,3130,1,1,1,0.0025),
  (30,3055,1,1,1,0.005),
  (30,3064,1,1,1,0.005),
  (30,3067,1,1,1,0.005),
  (30,3070,1,1,1,0.005),
  (30,3079,1,1,1,0.005),
  (30,3088,1,1,1,0.005),
  (30,3088,1,1,1,0.005),
  (30,3091,1,1,1,0.005),
  (48,3072,1,1,1,0.005),
  (54,3057,1,1,1,0.01),
  (54,3066,1,1,1,0.01),
  (54,3069,1,1,1,0.01),
  (54,3072,1,1,1,0.01),
  (54,3081,1,1,1,0.01),
  (54,3090,1,1,1,0.01),
  (54,3093,1,1,1,0.01),
  (54,3102,1,1,1,0.01),
  (54,3105,1,1,1,0.01),
  (54,3108,1,1,1,0.01),
  (54,3114,1,1,1,0.01),
  (54,3123,1,1,1,0.01),
  (59,3070,1,1,1,0.005),
  (59,3073,1,1,1,0.005),
  (59,3082,1,1,1,0.005),
  (59,3091,1,1,1,0.005),
  (59,3094,1,1,1,0.005),
  (59,3103,1,1,1,0.005),
  (59,3115,1,1,1,0.005),
  (59,3124,1,1,1,0.005),
  (59,3127,1,1,1,0.005),
  (59,3130,1,1,1,0.005),
  (79,3060,1,1,1,0.005),
  (79,3066,1,1,1,0.005),
  (79,3069,1,1,1,0.005),
  (79,3075,1,1,1,0.005),
  (79,3084,1,1,1,0.005),
  (79,3090,1,1,1,0.005),
  (79,3111,1,1,1,0.005),
  (79,3117,1,1,1,0.005),
  (79,3123,1,1,1,0.005),
  (79,3126,1,1,1,0.005),
  (79,3129,1,1,1,0.005),
  (84,3105,1,1,1,0.01),
  (84,3111,1,1,1,0.01),
  (84,3117,1,1,1,0.01),
  (84,3123,1,1,1,0.01),
  (84,3126,1,1,1,0.01),
  (84,3129,1,1,1,0.01),
  (84,3085,1,1,1,0.0025),
  (84,3091,1,1,1,0.0025),
  (84,3097,1,1,1,0.0025),
  (84,3103,1,1,1,0.0025),
  (84,3106,1,1,1,0.0025),
  (84,3112,1,1,1,0.0025),
  (89,3070,1,1,1,0.005),
  (89,3076,1,1,1,0.005),
  (89,3085,1,1,1,0.005),
  (89,3091,1,1,1,0.005),
  (89,3097,1,1,1,0.005),
  (89,3103,1,1,1,0.005),
  (89,3106,1,1,1,0.005),
  (89,3112,1,1,1,0.005),
  (89,3118,1,1,1,0.005),
  (89,3124,1,1,1,0.005),
  (48,3057,1,1,1,0.005),
  (48,3066,1,1,1,0.005),
  (48,3069,1,1,1,0.005),
  (48,3081,1,1,1,0.005),
  (48,3090,1,1,1,0.005),
  (48,3093,1,1,1,0.005),
  (48,3102,1,1,1,0.005),
  (48,3105,1,1,1,0.005),
  (48,3108,1,1,1,0.005),
  (48,3114,1,1,1,0.005),
  (48,3123,1,1,1,0.005),
  (48,3126,1,1,1,0.005),
  (48,3129,1,1,1,0.005),
  (54,3126,1,1,1,0.01),
  (54,3129,1,1,1,0.01),
  (79,3096,1,1,1,0.005),
  (79,3102,1,1,1,0.005),
  (79,3105,1,1,1,0.005),
  (84,3060,1,1,1,0.01),
  (84,3066,1,1,1,0.01),
  (84,3069,1,1,1,0.01),
  (84,3075,1,1,1,0.01),
  (84,3084,1,1,1,0.01),
  (84,3090,1,1,1,0.01),
  (84,3096,1,1,1,0.01),
  (89,3127,1,1,1,0.005),
  (89,3130,1,1,1,0.005),
  (54,3058,1,1,1,0.0025),
  (54,3067,1,1,1,0.0025),
  (54,3069,1,1,1,0.01),
  (54,3073,1,1,1,0.0025),
  (54,3082,1,1,1,0.0025),
  (54,3091,1,1,1,0.0025),
  (54,3094,1,1,1,0.0025),
  (54,3103,1,1,1,0.0025),
  (54,3106,1,1,1,0.0025),
  (54,3109,1,1,1,0.0025),
  (54,3115,1,1,1,0.0025),
  (54,3124,1,1,1,0.0025),
  (54,3127,1,1,1,0.0025),
  (54,3130,1,1,1,0.0025),
  (59,3058,1,1,1,0.005),
  (59,3067,1,1,1,0.005),
  (59,3106,1,1,1,0.005),
  (59,3109,1,1,1,0.005),
  (84,3102,1,1,1,0.01),
  (84,3061,1,1,1,0.0025),
  (84,3067,1,1,1,0.0025),
  (84,3070,1,1,1,0.0025),
  (84,3076,1,1,1,0.0025),
  (84,3118,1,1,1,0.0025),
  (84,3124,1,1,1,0.0025),
  (84,3127,1,1,1,0.0025),
  (84,3130,1,1,1,0.0025),
  (89,3061,1,1,1,0.005),
  (89,3067,1,1,1,0.005),
  (247,3072,1,1,1,0.005),
  (247,3057,1,1,1,0.005),
  (247,3066,1,1,1,0.005),
  (247,3069,1,1,1,0.005),
  (247,3081,1,1,1,0.005),
  (247,3090,1,1,1,0.005),
  (247,3093,1,1,1,0.005),
  (247,3102,1,1,1,0.005),
  (247,3105,1,1,1,0.005),
  (247,3108,1,1,1,0.005),
  (247,3114,1,1,1,0.005),
  (247,3123,1,1,1,0.005),
  (247,3126,1,1,1,0.005),
  (247,3129,1,1,1,0.005),
  (247,5003,1,1,1,0.005),
  (248,3057,1,1,1,0.01),
  (248,3066,1,1,1,0.01),
  (248,3069,1,1,1,0.01),
  (248,3072,1,1,1,0.01),
  (248,3081,1,1,1,0.01),
  (248,3090,1,1,1,0.01),
  (248,3093,1,1,1,0.01),
  (248,3102,1,1,1,0.01),
  (248,3105,1,1,1,0.01),
  (248,3108,1,1,1,0.01),
  (248,3114,1,1,1,0.01),
  (248,3123,1,1,1,0.01),
  (248,3126,1,1,1,0.01),
  (248,3129,1,1,1,0.01),
  (248,3058,1,1,1,0.0025),
  (248,3067,1,1,1,0.0025),
  (248,3069,1,1,1,0.01),
  (248,3073,1,1,1,0.0025),
  (248,3082,1,1,1,0.0025),
  (248,3091,1,1,1,0.0025),
  (248,3094,1,1,1,0.0025),
  (248,3103,1,1,1,0.0025),
  (248,3106,1,1,1,0.0025),
  (248,3109,1,1,1,0.0025),
  (248,3115,1,1,1,0.0025),
  (248,3124,1,1,1,0.0025),
  (248,3127,1,1,1,0.0025),
  (248,3130,1,1,1,0.0025),
  (248,5003,1,1,1,0.01),
  (248,5004,1,1,1,0.0025),
  (249,3070,1,1,1,0.005),
  (249,3073,1,1,1,0.005),
  (249,3082,1,1,1,0.005),
  (249,3091,1,1,1,0.005),
  (249,3094,1,1,1,0.005),
  (249,3103,1,1,1,0.005),
  (249,3115,1,1,1,0.005),
  (249,3124,1,1,1,0.005),
  (249,3127,1,1,1,0.005),
  (249,3130,1,1,1,0.005),
  (249,3058,1,1,1,0.005),
  (249,3067,1,1,1,0.005),
  (249,3106,1,1,1,0.005),
  (249,3109,1,1,1,0.005),
  (249,5004,1,1,1,0.005),
  (250,3008,1,1,1,0.005),
  (250,3063,1,1,1,0.005),
  (250,3066,1,1,1,0.005),
  (250,3069,1,1,1,0.005),
  (250,3078,1,1,1,0.005),
  (250,3087,1,1,1,0.005),
  (250,3090,1,1,1,0.005),
  (250,3099,1,1,1,0.005),
  (250,3102,1,1,1,0.005),
  (250,3105,1,1,1,0.005),
  (250,3120,1,1,1,0.005),
  (250,3123,1,1,1,0.005),
  (250,3126,1,1,1,0.005),
  (250,3129,1,1,1,0.005),
  (250,5003,1,1,1,0.005),
  (251,3008,1,1,1,0.01),
  (251,3063,1,1,1,0.01),
  (251,3066,1,1,1,0.01),
  (251,3069,1,1,1,0.01),
  (251,3078,1,1,1,0.01),
  (251,3087,1,1,1,0.01),
  (251,3090,1,1,1,0.01),
  (251,3099,1,1,1,0.01),
  (251,3102,1,1,1,0.01),
  (251,3105,1,1,1,0.01),
  (251,3120,1,1,1,0.01),
  (251,3123,1,1,1,0.01),
  (251,3126,1,1,1,0.01),
  (251,3129,1,1,1,0.01),
  (251,3055,1,1,1,0.0025),
  (251,3064,1,1,1,0.0025),
  (251,3067,1,1,1,0.0025),
  (251,3070,1,1,1,0.0025),
  (251,3079,1,1,1,0.0025),
  (251,3088,1,1,1,0.0025),
  (251,3091,1,1,1,0.0025),
  (251,3100,1,1,1,0.0025),
  (251,3103,1,1,1,0.0025),
  (251,3106,1,1,1,0.0025),
  (251,3121,1,1,1,0.0025),
  (251,3124,1,1,1,0.0025),
  (251,3127,1,1,1,0.0025),
  (251,3130,1,1,1,0.0025),
  (251,5003,1,1,1,0.01),
  (251,5004,1,1,1,0.0025),
  (252,3100,1,1,1,0.005),
  (252,3103,1,1,1,0.005),
  (252,3106,1,1,1,0.005),
  (252,3121,1,1,1,0.005),
  (252,3124,1,1,1,0.005),
  (252,3127,1,1,1,0.005),
  (252,3130,1,1,1,0.005),
  (252,3055,1,1,1,0.005),
  (252,3064,1,1,1,0.005),
  (252,3067,1,1,1,0.005),
  (252,3070,1,1,1,0.005),
  (252,3079,1,1,1,0.005),
  (252,3088,1,1,1,0.005),
  (252,3088,1,1,1,0.005),
  (252,3091,1,1,1,0.005),
  (252,5004,1,1,1,0.005),
  (253,3060,1,1,1,0.005),
  (253,3066,1,1,1,0.005),
  (253,3069,1,1,1,0.005),
  (253,3075,1,1,1,0.005),
  (253,3084,1,1,1,0.005),
  (253,3090,1,1,1,0.005),
  (253,3111,1,1,1,0.005),
  (253,3117,1,1,1,0.005),
  (253,3123,1,1,1,0.005),
  (253,3126,1,1,1,0.005),
  (253,3129,1,1,1,0.005),
  (253,3096,1,1,1,0.005),
  (253,3102,1,1,1,0.005),
  (253,3105,1,1,1,0.005),
  (253,5003,1,1,1,0.005),
  (254,3105,1,1,1,0.01),
  (254,3111,1,1,1,0.01),
  (254,3117,1,1,1,0.01),
  (254,3123,1,1,1,0.01),
  (254,3126,1,1,1,0.01),
  (254,3129,1,1,1,0.01),
  (254,3085,1,1,1,0.0025),
  (254,3091,1,1,1,0.0025),
  (254,3097,1,1,1,0.0025),
  (254,3103,1,1,1,0.0025),
  (254,3106,1,1,1,0.0025),
  (254,3112,1,1,1,0.0025),
  (254,3060,1,1,1,0.01),
  (254,3066,1,1,1,0.01),
  (254,3069,1,1,1,0.01),
  (254,3075,1,1,1,0.01),
  (254,3084,1,1,1,0.01),
  (254,3090,1,1,1,0.01),
  (254,3096,1,1,1,0.01),
  (254,3102,1,1,1,0.01),
  (254,3061,1,1,1,0.0025),
  (254,3067,1,1,1,0.0025),
  (254,3070,1,1,1,0.0025),
  (254,3076,1,1,1,0.0025),
  (254,3118,1,1,1,0.0025),
  (254,3124,1,1,1,0.0025),
  (254,3127,1,1,1,0.0025),
  (254,3130,1,1,1,0.0025),
  (254,5003,1,1,1,0.01),
  (254,5004,1,1,1,0.0025),
  (255,3070,1,1,1,0.005),
  (255,3076,1,1,1,0.005),
  (255,3085,1,1,1,0.005),
  (255,3091,1,1,1,0.005),
  (255,3097,1,1,1,0.005),
  (255,3103,1,1,1,0.005),
  (255,3106,1,1,1,0.005),
  (255,3112,1,1,1,0.005),
  (255,3118,1,1,1,0.005),
  (255,3124,1,1,1,0.005),
  (255,3127,1,1,1,0.005),
  (255,3130,1,1,1,0.005),
  (255,3061,1,1,1,0.005),
  (255,3067,1,1,1,0.005),
  (255,5004,1,1,1,0.005);
  
  --DEBUG: Before
  --SELECT * from artifactloot
  --JOIN calibrationtemplateitems ON calibrationtemplateitems.definition=artifactloot.definition
  --JOIN #TEMP_OLD_MK2CT_LOOTS AS old_arti ON old_arti.definition=calibrationtemplateitems.targetdefinition and old_arti.artifacttype=artifactloot.artifacttype
  
  
  --UPDATE ONLY THE CHANCE OF THE PREVIOUSLY INSERTED/SWAPPED MK2 CT CAPSULES
  --The Chance column will now match 1:1 the old table chances +++ chance reduction for loot balance
  
  PRINT N'UPDATE ARTI LOOT CHANCE W/ RECOVERED CHANCES FROM VANILLA LOOT TABLE +++ CHANCE TWEAK!!!'
  UPDATE artifactloot
  SET chance = old_arti.chance/2.0
  FROM calibrationtemplateitems AS capsules
  JOIN #TEMP_OLD_MK2CT_LOOTS AS old_arti ON old_arti.definition=capsules.targetdefinition WHERE old_arti.artifacttype=artifactloot.artifacttype
  
  --DEBUG: After
  --SELECT * from artifactloot
  --JOIN calibrationtemplateitems ON calibrationtemplateitems.definition=artifactloot.definition
  --JOIN #TEMP_OLD_MK2CT_LOOTS AS old_arti ON old_arti.definition=calibrationtemplateitems.targetdefinition and old_arti.artifacttype=artifactloot.artifacttype
  
  
  DROP TABLE IF EXISTS #TEMP_OLD_MK2CT_LOOTS
  
  GO
  
  
  --2_ECON_mk2CT_template_values
  USE [perpetuumsa]
  GO
  
  ---[ECONOMY REQUEST]  MK2 CT Base values---
  --Base MK2 CT pt values set to 10% of vanilla
  --A = low (50->5)
  --B = mid (100->10)
  --C = hi (150->15)
  
  UPDATE
      [dynamiccalibrationtemplates]
  SET
      [dynamiccalibrationtemplates].materialefficiency = CASE 
  		WHEN defs.definitionname like '%_mk2_A_%' THEN 5
  		WHEN defs.definitionname like '%_mk2_B_%' THEN 10
  		WHEN defs.definitionname like '%_mk2_C_%' THEN 15
  		ELSE 5 END,
      [dynamiccalibrationtemplates].timeefficiency = CASE 
  		WHEN defs.definitionname like '%_mk2_A_%' THEN 5
  		WHEN defs.definitionname like '%_mk2_B_%' THEN 10
  		WHEN defs.definitionname like '%_mk2_C_%' THEN 15
  		ELSE 5 END
  FROM
      [dynamiccalibrationtemplates] AS mk2CTs
      INNER JOIN entitydefaults AS defs
          ON mk2CTs.definition = defs.definition
  
  GO
  
  
  
  
  --3_0_BALANCE_MK2_PREP__part_0
  USE [perpetuumsa]
  GO
  
  --MK2 CHASSISBONUS AND AGGREGATEVALUES PREP SCRIPT--
  --Clears ALL current mk2 bonuses, and replaces with new entries that are copies of their mk1 counterparts
  --Sets ALL current mk2 stats (aggregatevalues) to be equivalent to their mk1 counterparts
  --This is to be run BEFORE!!! any additions/changes to MK2 bonuses and bot stats
  --The intent is to capture all mk1 stat and bonus changes, and then selectively add and modify mk2 attributes
  --
  
  
  PRINT N'MK2 BALANCE PREP SCRIPT - SETS ALL MK2 BONUSES AND AGGVALUE STATS TO MK1 STATE';
  PRINT N'MK1 CHANGES SHOULD BE COMPLETED BEFORE THIS SCRIPT IS RUN!';
  
  --Robot part category - for entitydefault lookup
  DECLARE @cf_robot_component bigint;
  SET @cf_robot_component = (SELECT TOP 1 value FROM categoryFlags WHERE name='cf_robot_components');
  
  DROP TABLE IF EXISTS #TEMP
  DROP TABLE IF EXISTS #MK1TOMK2DEF
  DROP TABLE IF EXISTS #MK1TOMK2VALS
  
  --Table to map the definitonnames
  CREATE TABLE #TEMP
  ( 
    mk1defname varchar(100),
    mk2defname varchar(100)
  );
  
  --Table to map actual definitons
  CREATE TABLE #MK1TOMK2DEF
  ( 
    mk1def int,
    mk2def int
  );
  
  --Table to map aggregateValues
  CREATE TABLE #MK1TOMK2VALS
  (
  	mk1def int,
  	mk2def int,
  	field int,
  	value float
  );
  
  --Relate mk1 and mk2 components with string manipulation on definitionnames (!)
  INSERT INTO #TEMP (mk1defname, mk2defname)
  SELECT REPLACE(definitionname, '_mk2', ''), definitionname from entitydefaults 
  WHERE definitionname in (SELECT definitionname FROM entitydefaults WHERE definitionname like '%_mk2%' and categoryflags = categoryflags | @cf_robot_component);
  
  --Create map between mk1 and mk2 definitions
  INSERT INTO #MK1TOMK2DEF (mk1def, mk2def)
  SELECT 
  (SELECT TOP 1 definition FROM entitydefaults WHERE definitionname=mk1defname), 
  (SELECT TOP 1 definition FROM entitydefaults WHERE definitionname=mk2defname)
   FROM #TEMP;
  
  
  --mk1-mk2 pairs with aggfield and value of the mk1 definition
  INSERT INTO #MK1TOMK2VALS (mk1def, mk2def, field, value)
  SELECT mk1def, mk2def, field, value FROM aggregatevalues
  JOIN #MK1TOMK2DEF ON aggregatevalues.definition=mk1def
  WHERE mk1def = aggregatevalues.definition
  
  --BOT STATS
  --UPDATE ALL OF THE MK2 AGGVALUES TO MK1 STATE
  UPDATE aggregatevalues
  SET value = mk2Vals.value
  FROM aggregatevalues AS aggVals
  JOIN #MK1TOMK2VALS AS mk2Vals ON mk2Vals.mk2def=aggVals.definition AND mk2Vals.field=aggVals.field
  
  --BONUSES
  --REMOVE ALL CURRENT MK2 BONUSES
  DELETE FROM chassisbonus
  WHERE chassisbonus.definition IN (SELECT mk2def FROM #MK1TOMK2DEF)
  
  --INSERT MK1 BONUSES TO ALL MK2 DEFINITONS (mk2 bonuses are mk1 + extra) -- Assumes mk1 bonuses are entact!
  INSERT INTO [dbo].[chassisbonus]
             ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
  SELECT mk2def, extension, bonus, note, targetpropertyID, effectenhancer FROM chassisbonus
  JOIN #MK1TOMK2DEF ON chassisbonus.definition=mk1def;
  
  
  --cleanup garbage
  DROP TABLE IF EXISTS #TEMP
  DROP TABLE IF EXISTS #MK1TOMK2DEF
  DROP TABLE IF EXISTS #MK1TOMK2VALS
  
  PRINT N'MK2 AGGVALUE-STATS AND BONUSES ARE NOW == TO MK1';
  GO
  
  
  
  --3_1_BALANCE_MK2_cargos__part_1
  USE [perpetuumsa]
  GO
  
  --ALL MK2 Cargos 150% of mk1 cargo
  PRINT N'MK2 CARGO BALANCE';
  UPDATE entitydefaults
  SET options='#capacity=f4.5'
  WHERE definitionname = 'def_robot_inventory_combat_ewrunner_mk2';
  
  UPDATE entitydefaults
  SET options='#capacity=f5.6'
  WHERE definitionname = 'def_robot_inventory_combat_runner_mk2';
  
  UPDATE entitydefaults
  SET options='#capacity=f9.0'
  WHERE definitionname = 'def_robot_inventory_combat_crawler_mk2';
  
  UPDATE entitydefaults
  SET options='#capacity=f11.25'
  WHERE definitionname = 'def_robot_inventory_combat_ewmech_indy_runner_mk2';
  
  UPDATE entitydefaults
  SET options='#capacity=f13.5'
  WHERE definitionname = 'def_robot_inventory_combat_mech_mk2';
  
  UPDATE entitydefaults
  SET options='#capacity=f18.0'
  WHERE definitionname = 'def_robot_inventory_combat_heavymech_mk2';
  
  UPDATE entitydefaults
  SET options='#capacity=f22.5'
  WHERE definitionname = 'def_robot_inventory_indy_mech_mk2';
  
  UPDATE entitydefaults
  SET options='#capacity=f31.5'
  WHERE definitionname = 'def_robot_inventory_indy_heavymech_mk2';
  
  UPDATE entitydefaults
  SET options='#capacity=f1080.0'
  WHERE definitionname = 'def_robot_inventory_lithus_mk2';
  
  UPDATE entitydefaults
  SET options='#capacity=f180.0'
  WHERE definitionname = 'def_robot_inventory_sequer_mk2';
  
  UPDATE entitydefaults
  SET options='#capacity=f3240.0'
  WHERE definitionname = 'def_robot_inventory_scarab_mk2';
  
  GO
  
  
  --3_2_BALANCE_MK2_botstats_v1__part_2
  USE [perpetuumsa]
  GO
  
  DECLARE @defname_head varchar(100);
  DECLARE @defname_chassis varchar(100);
  
  DECLARE @definitionID int;
  DECLARE @aggvalueID int;
  
  DECLARE @cpu_field int;
  DECLARE @reactor_field int;
  DECLARE @targets_field int;
  
  DECLARE @cpu float;
  DECLARE @reactor float;
  DECLARE @targets float;
  DECLARE @mass float;
  
  SET @cpu_field = (SELECT TOP 1 id from aggregatefields WHERE [name] = 'cpu_max' ORDER BY [name] DESC);
  SET @reactor_field = (SELECT TOP 1 id from aggregatefields WHERE [name] = 'powergrid_max' ORDER BY [name] DESC);
  SET @targets_field = (SELECT TOP 1 id from aggregatefields WHERE [name] = 'locked_targets_max' ORDER BY [name] DESC);
  
  
  DECLARE @MK2STATS TABLE
  (
    headname varchar(100), 
    chassisname varchar(100), 
    cpu float, 
    reactor float, 
    targets int,
    mass float
  );
  
  --mk2 bot stat changes
  INSERT INTO @MK2STATS VALUES
  ('def_yagel_head_mk2', 'def_yagel_chassis_mk2', 170, 165, 5, 6200),
  ('def_prometheus_head_mk2', 'def_prometheus_chassis_mk2', 170, 198, 5, 6200),
  ('def_castel_head_mk2', 'def_castel_chassis_mk2', 224, 148, 5, 5000),
  ('def_argano_head_mk2', 'def_argano_chassis_mk2', 192, 198, 5, 7500),
  ('def_laird_head_mk2', 'def_laird_chassis_mk2', 192, 209, 5, 7500),
  ('def_cameleon_head_mk2', 'def_cameleon_chassis_mk2', 286, 176, 6, 5000),
  ('def_intakt_head_mk2', 'def_intakt_chassis_mk2', 209, 165, 6, 5000),
  ('def_troiar_head_mk2', 'def_troiar_chassis_mk2', 242, 192, 6, 5100),
  ('def_arbalest_head_mk2', 'def_arbalest_chassis_mk2', 275, 346, 6, 11000),
  ('def_baphomet_mk2_head', 'def_baphomet_mk2_chassis', 275, 418, 6, 11000),
  ('def_waspish_head_mk2', 'def_waspish_chassis_mk2', 302, 330, 6, 9500),
  ('def_sequer_head_mk2', 'def_sequer_chassis_mk2', 198, 198, 5, 9600),
  ('def_kain_head_mk2', 'def_kain_chassis_mk2', 330, 990, 7, 25000),
  ('def_artemis_head_mk2', 'def_artemis_chassis_mk2', 280, 1210, 7, 25000),
  ('def_tyrannos_head_mk2', 'def_tyrannos_chassis_mk2', 363, 990, 7, 22500),
  ('def_termis_head_mk2', 'def_termis_chassis_mk2', 330, 825, 6, 16200),
  ('def_gargoyle_head_mk2', 'def_gargoyle_chassis_mk2', 330, 825, 6, 16200),
  ('def_vagabond_head_mk2', 'def_vagabond_chassis_mk2', 495, 660, 9, 14500),
  ('def_zenith_head_mk2', 'def_zenith_chassis_mk2', 467, 825, 9, 14500),
  ('def_ictus_head_mk2', 'def_ictus_chassis_mk2', 544, 1045, 9, 15500),
  ('def_mesmer_head_mk2', 'def_mesmer_chassis_mk2', 401, 1182, 8, 30000),
  ('def_seth_head_mk2', 'def_seth_chassis_mk2', 346, 1512, 8, 30000),
  ('def_gropho_head_mk2', 'def_gropho_chassis_mk2', 459, 1127, 8, 26500),
  ('def_riveler_head_mk2', 'def_riveler_chassis_mk2', 450, 880, 7, 42000),
  ('def_symbiont_head_mk2', 'def_symbiont_chassis_mk2', 450, 880, 7, 42000),
  ('def_lithus_head_mk2', 'def_lithus_chassis_mk2', 495, 825, 5, 78000),
  ('def_scarab_head_mk2', 'def_scarab_chassis_mk2', 440, 660, 5, 54000);
  
  
  
  --UPDATE THE CPUS
  UPDATE
      aggregatevalues
  SET
      aggregatevalues.value = mk2stats.cpu
  FROM
      aggregatevalues AS aggvalue
      INNER JOIN @MK2STATS AS mk2stats
          ON aggvalue.definition = (SELECT TOP 1 definition FROM entitydefaults WHERE definitionname=mk2stats.headname)
  WHERE
      aggvalue.id = (SELECT TOP 1 id from aggregatevalues WHERE [definition] = 
  	(SELECT TOP 1 definition FROM entitydefaults WHERE definitionname=mk2stats.headname)
  	 AND [field]=@cpu_field ORDER BY definition DESC);
  
  
  --UPDATE THE REACTORS
  UPDATE
      aggregatevalues
  SET
      aggregatevalues.value = mk2stats.reactor
  FROM
      aggregatevalues AS aggvalue
      INNER JOIN @MK2STATS AS mk2stats
          ON aggvalue.definition = (SELECT TOP 1 definition FROM entitydefaults WHERE definitionname=mk2stats.chassisname)
  WHERE
      aggvalue.id = (SELECT TOP 1 id from aggregatevalues WHERE [definition] = 
  	(SELECT TOP 1 definition FROM entitydefaults WHERE definitionname=mk2stats.chassisname)
  	 AND [field]=@reactor_field ORDER BY definition DESC);
  
  
  --UPDATE THE MAX TARGETS
  UPDATE
      aggregatevalues
  SET
      aggregatevalues.value = mk2stats.targets
  FROM
      aggregatevalues AS aggvalue
      INNER JOIN @MK2STATS AS mk2stats
          ON aggvalue.definition = (SELECT TOP 1 definition FROM entitydefaults WHERE definitionname=mk2stats.headname)
  WHERE
      aggvalue.id = (SELECT TOP 1 id from aggregatevalues WHERE [definition] = 
  	(SELECT TOP 1 definition FROM entitydefaults WHERE definitionname=mk2stats.headname)
  	 AND [field]=@targets_field ORDER BY definition DESC);
  
  
  --UPDATE THE MASSES!!!!
  UPDATE
      entitydefaults
  SET
      entitydefaults.mass = mk2stats.mass
  FROM
      entitydefaults AS defs
      INNER JOIN @MK2STATS AS mk2stats
          ON defs.definition = (SELECT TOP 1 definition FROM entitydefaults WHERE definitionname=mk2stats.chassisname)
  WHERE
      defs.definition = (SELECT TOP 1 definition FROM entitydefaults WHERE definitionname=mk2stats.chassisname);
  
  
  GO
  
  
  --3_3_BALANCE_MK2_Bonuses__part_3
  USE [perpetuumsa]
  GO
  
  ----------------MK2 Bonus additions----------------
  --All are insertions of new Chassibonus to the Head robot component of each mk2
  --This should make the mk2 have the same bonus table as a mk1 + this one bonus
  --NOTE: this is to run AFTER the mk2 balance prep script
  
  PRINT N'ALL MK2 HI-TECH SPEC BONUSES';
  
  DECLARE @definitionID int;
  DECLARE @extensionID int;
  DECLARE @aggfieldID int;
  DECLARE @chassisbonusID int;
  
  DECLARE @railgun_cycle_field int;
  DECLARE @railgun_cycle_bonus float;
  
  DECLARE @ecm_strength_field int;
  DECLARE @ecm_strength_bonus float;
  
  DECLARE @missile_range_field int;
  DECLARE @missile_range_bonus float;
  
  DECLARE @neutralize_field int;
  DECLARE @neutralize_bonus float;
  
  DECLARE @drain_field int;
  DECLARE @drain_bonus float;
  
  DECLARE @crit_field int;
  DECLARE @crit_bonus float;
  
  DECLARE @suppress_time_field int;
  DECLARE @suppress_time_bonus float;
  
  DECLARE @suppress_range_field int;
  DECLARE @suppress_range_bonus float;
  
  DECLARE @harvesting_amount_field int;
  DECLARE @harvesting_amount_bonus float;
  
  DECLARE @mining_amount_field int;
  DECLARE @mining_amount_bonus float;
  
  DECLARE @demob_resist_field int;
  DECLARE @demob_resist_bonus float;
  
  
  SET @railgun_cycle_field = (SELECT TOP 1 id from aggregatefields WHERE[name] = 'railgun_cycle_time_modifier' ORDER BY [name] DESC);
  SET @railgun_cycle_bonus = -0.01;
  
  SET @ecm_strength_field = (SELECT TOP 1 id from aggregatefields WHERE[name] = 'ecm_strength_modifier' ORDER BY [name] DESC);
  SET @ecm_strength_bonus = 0.01;
  
  SET @missile_range_field = (SELECT TOP 1 id from aggregatefields WHERE[name] = 'missile_range_modifier' ORDER BY [name] DESC);
  SET @missile_range_bonus = 0.01;
  
  SET @neutralize_field = (SELECT TOP 1 id from aggregatefields WHERE[name] = 'energy_neutralized_amount_modifier' ORDER BY [name] DESC);
  SET @neutralize_bonus = 0.01;
  
  SET @drain_field =(SELECT TOP 1 id from aggregatefields WHERE[name] = 'energy_vampired_amount_modifier' ORDER BY [name] DESC);
  SET @drain_bonus = 0.01;
  
  SET @crit_field  = (SELECT TOP 1 id from aggregatefields WHERE[name] = 'critical_hit_chance_modifier' ORDER BY [name] DESC);
  SET @crit_bonus = 0.01;
  
  SET @suppress_time_field = (SELECT TOP 1 id from aggregatefields WHERE[name] = 'effect_enhancer_sensor_dampener_locking_time_modifier' ORDER BY [name] DESC);
  SET @suppress_time_bonus = 0.01;
  
  SET @suppress_range_field =(SELECT TOP 1 id from aggregatefields WHERE[name] = 'effect_enhancer_sensor_dampener_locking_range_modifier' ORDER BY [name] DESC);
  SET @suppress_range_bonus = 0.01;
  
  SET @mining_amount_field =(SELECT TOP 1 id from aggregatefields WHERE[name] = 'mining_amount_modifier' ORDER BY [name] DESC);
  SET @mining_amount_bonus = 0.01;
  
  SET @harvesting_amount_field =(SELECT TOP 1 id from aggregatefields WHERE[name] = 'harvesting_amount_modifier' ORDER BY [name] DESC);
  SET @harvesting_amount_bonus = 0.01;
  
  SET @demob_resist_field = (SELECT TOP 1 id from aggregatefields WHERE[name] = 'massiveness' ORDER BY [name] DESC);
  SET @demob_resist_bonus = 0.01;
  
  
  --The only extenstion being used here
  PRINT N'ext_high_tech_specialist';
  SET @extensionID = (SELECT TOP 1 extensionid from dbo.extensions WHERE extensionname = 'ext_high_tech_specialist');
  
  
  --NUMIQOL COMBAT
  PRINT N'def_yagel_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_yagel_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @railgun_cycle_bonus, '', @railgun_cycle_field, 0);
  
  
  PRINT N'def_arbalest_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_arbalest_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @railgun_cycle_bonus, '', @railgun_cycle_field, 0);
  
  
  PRINT N'def_kain_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_kain_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @railgun_cycle_bonus, '', @railgun_cycle_field, 0);
  
  
  PRINT N'def_mesmer_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_mesmer_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @railgun_cycle_bonus, '', @railgun_cycle_field, 0);
  
  --NUMIQUOL EWAR
  PRINT N'def_vagabond_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_vagabond_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @ecm_strength_bonus, '', @ecm_strength_field, 0);
  
  
  PRINT N'def_cameleon_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_cameleon_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @ecm_strength_bonus, '', @ecm_strength_field, 0);
  
  --PELISTAL COMBAT
  PRINT N'def_castel_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_castel_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @missile_range_bonus, '', @missile_range_field, 0);
  
  
  PRINT N'def_waspish_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_waspish_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @missile_range_bonus, '', @missile_range_field, 0);
  
  
  PRINT N'def_tyrannos_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_tyrannos_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @missile_range_bonus, '', @missile_range_field, 0);
  
  
  PRINT N'def_gropho_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_gropho_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @missile_range_bonus, '', @missile_range_field, 0);
  
  --PELISTAL EWAR
  PRINT N'def_troiar_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_troiar_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @neutralize_bonus, '', @neutralize_field, 0);
  
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @drain_bonus, '', @drain_field, 0);
  
  
  PRINT N'def_ictus_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_ictus_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @neutralize_bonus, '', @neutralize_field, 0);
  
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @drain_bonus, '', @drain_field, 0);
  
  --THELODICA COMBAT
  PRINT N'def_prometheus_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_prometheus_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @crit_bonus, '', @crit_field, 0);
  
  
  PRINT N'def_baphomet_mk2_head';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_baphomet_mk2_head' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @crit_bonus, '', @crit_field, 0);
  
  
  PRINT N'def_artemis_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_artemis_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @crit_bonus, '', @crit_field, 0);
  
  
  PRINT N'def_seth_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_seth_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @crit_bonus, '', @crit_field, 0);
  
  --THELODICA EWAR
  PRINT N'def_zenith_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_zenith_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @suppress_range_bonus, '', @suppress_range_field, 0);
  
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @suppress_time_bonus, '', @suppress_time_field, 0);
  
  
  PRINT N'def_intakt_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_intakt_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @suppress_range_bonus, '', @suppress_range_field, 0);
  
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @suppress_time_bonus, '', @suppress_time_field, 0);
  
  
  
  --MINERS
  PRINT N'def_argano_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_argano_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @mining_amount_bonus, '', @mining_amount_field, 0);
  
  
  PRINT N'def_termis_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_termis_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @mining_amount_bonus, '', @mining_amount_field, 0);
  
  
  PRINT N'def_riveler_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_riveler_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @mining_amount_bonus, '', @mining_amount_field, 0);
  
  
  --HARVESTERS
  PRINT N'def_symbiont_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_symbiont_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @harvesting_amount_bonus, '', @harvesting_amount_field, 0);
  
  
  PRINT N'def_gargoyle_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_gargoyle_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @harvesting_amount_bonus, '', @harvesting_amount_field, 0);
  
  
  PRINT N'def_laird_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_laird_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @harvesting_amount_bonus, '', @harvesting_amount_field, 0);
  
  
  --HAULERS
  PRINT N'def_scarab_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_scarab_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @demob_resist_bonus, '', @demob_resist_field, 0);
  
  
  PRINT N'def_lithus_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_lithus_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @demob_resist_bonus, '', @demob_resist_field, 0);
  
  
  PRINT N'def_sequer_head_mk2';
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_sequer_head_mk2' ORDER BY definition DESC);
  INSERT INTO [dbo].[chassisbonus] ([definition],[extension],[bonus],[note],[targetpropertyID],[effectenhancer])
                  VALUES (@definitionID, @extensionID, @demob_resist_bonus, '', @demob_resist_field, 0);
  
  GO
  
  
  --3_4_BALANCE_MK2_exceptions__part_4
  USE [perpetuumsa]
  GO
  
  PRINT N'MK2 STAT AND BALANCE RULE EXCEPTIONS';
  -------------Scarab MK2 Exceptions----
  ---head/chassis/leg
  ---Vanilla mk2 5/2/2
  ---OPP     mk1 4/2/3
  ---OPP     mk2 4/2/3
  
  ---Exceptional mk1 changes to fast-forward to mk2s
  --HM chassis misc slots 4->2
  --Gropho mk1 chassis options = '#height=f0.8#slotFlags=4d2,d2,2d2,2d2,4d2,4d2,4d0'
  --Mesmer mk1 chassis options = #height=f1.1#slotFlags=46d1,d1,d1,2d1,d1,4d1,4d0
  --Seth mk1 chassis options = '#height=f0.75#slotFlags=46d1,d1,d1,2d1,d1,4d1'
  
  
  DECLARE @definitionID int;
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_scarab_leg_mk2' ORDER BY definition DESC);
  UPDATE entitydefaults SET options='#height=f1.5#slotFlags=420,20,20' WHERE definition=@definitionID;
  
  
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_scarab_head_mk2' ORDER BY definition DESC);
  UPDATE entitydefaults SET options='#height=f0.1#slotFlags=48,8,8,8' WHERE definition=@definitionID;
  
  
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_gropho_chassis_mk2' ORDER BY definition DESC);
  UPDATE entitydefaults SET options='#height=f0.8#slotFlags=4d2,d2,2d2,2d2,4d2,4d2,4d0' WHERE definition=@definitionID;
  
  
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_mesmer_chassis_mk2' ORDER BY definition DESC);
  UPDATE entitydefaults SET options='#height=f1.1#slotFlags=46d1,d1,d1,2d1,d1,4d1,4d0' WHERE definition=@definitionID;
  
  
  SET @definitionID = (SELECT TOP 1 definition from entitydefaults WHERE [definitionname] = 'def_seth_chassis_mk2' ORDER BY definition DESC);
  UPDATE entitydefaults SET options='#height=f0.75#slotFlags=46d1,d1,d1,2d1,d1,4d1' WHERE definition=@definitionID;
  
  GO
  
  
  
  
  --4_0_ECON_artifactloot_entitydef_updates
  USE perpetuumsa
  GO
  
  --Two updates: Kernel increase (artifact loot), and T0/t3- volume changes (entitydefault update)
  --Basic sanity checks to guard against running multiple times because values are updated based on previous assumed state
  
  ------------Artifact Loot: Kernel Update------------
  --Set the maxquantity to 2x previous (vanilla, where max-maxquantity==1600)
  --Set minquantity to 50% of max
  
  DECLARE @kernel_max_multi float;
  DECLARE @kernel_min_max_factor float;
  
  SET @kernel_max_multi = 2.0;
  SET @kernel_min_max_factor = 0.5;
  
  
  DECLARE @cf_kernel bigint;
  SET @cf_kernel = (SELECT TOP 1 value FROM categoryFlags WHERE name='cf_kernels');
  
  
  --Sanity Check that maximum kernels in table are approximately what we expect from vanilla (before this change)
  DECLARE @kernel_check bit;
  SET @kernel_check = 
  	CASE 
  		WHEN 1601 > (SELECT TOP 1 maxquantity FROM artifactloot
  			JOIN entitydefaults ON artifactloot.definition=entitydefaults.definition 
  			WHERE categoryflags=@cf_kernel AND definitionname LIKE 'def_kernel_%' ORDER BY maxquantity DESC)
  			THEN 1
  		ELSE 0
  	END;
  
  IF @kernel_check=1
  	PRINT N'Kernel loot max quantity <= 1600 -- WILL RUN UPDATE!';
  ELSE
  	PRINT N'Kernel loot max quantity >> 1600 -- Update should NOT be executed';
  
  IF @kernel_check=1
  	--Set the MaxQuantity to 2x original
  	UPDATE artifactloot
  	SET
  	maxquantity = maxquantity*@kernel_max_multi
  	FROM artifactloot as loot
  	JOIN entitydefaults as defs on loot.definition=defs.definition 
  	WHERE defs.categoryflags=@cf_kernel AND defs.definitionname like 'def_kernel_%';
  ELSE
  	PRINT N'skipped update maxquantity on kernel loot';
  
  
  IF @kernel_check=1
  	--Using the NEW maxquantity value, after update, Set MinQuantity as 1/2 of max
  	UPDATE artifactloot
  	SET
  	minquantity = maxquantity*@kernel_min_max_factor
  	FROM artifactloot as loot
  	JOIN entitydefaults as defs on loot.definition=defs.definition 
  	WHERE defs.categoryflags=@cf_kernel AND defs.definitionname like 'def_kernel_%';
  ELSE
  	PRINT N'skipped update maxquantity on kernel loot';
  
  GO
  
  
  
  ----------------Artifact Loot: T3- T0 volumes-------------
  --UPDATE to ENTITYDEFAULTS
  --Reduce VOLUME properties of all T0/T3- Modules to increase loot haul potential of artifacters
  --Will run if max volume found to be 2.0 (current max size)
  --Will not reduce volumes < 0.1
  
  
  DECLARE @artifact_module_size_factor float;
  
  SET @artifact_module_size_factor = 0.5;
  
  DECLARE @volume_check bit;
  SET @volume_check = 
  	CASE 
  		WHEN (2.0 <= (SELECT TOP 1 volume from entitydefaults WHERE (tiertype=3 and tierlevel=3) or (tiertype=1 and tierlevel=0) and definitionname like 'def_artifact_%' ORDER BY volume DESC)) THEN 1
  		ELSE 0
  	END;
  
  IF @volume_check=1
  	PRINT N'Max volume of items is >=2  WILL RUN UPDATE!';
  ELSE
  	PRINT N'Max volume of items is <2 -- Update should NOT be executed';
  
  --Sanity check: Max module volume is 2.0
  --Run update IFF this module size still exists
  IF @volume_check=1
  	UPDATE entitydefaults
  	SET volume = volume * @artifact_module_size_factor
  	WHERE (tiertype=3 and tierlevel=3) or (tiertype=1 and tierlevel=0) and definitionname like 'def_artifact_%' and volume>=0.1;
  ELSE
  	PRINT N'Update SKIPPED -- must have been run before';
  
  GO
  
  