|
| 1 | +-- You like artifact but no have artifact? Get artifake instead, just as good, is two more even! |
| 2 | +local utils = require 'utils' |
| 3 | + |
| 4 | +validArgs = validArgs or utils.invert({ |
| 5 | + 'help', |
| 6 | + 'material', |
| 7 | + 'item', |
| 8 | + 'name', |
| 9 | + 'r', |
| 10 | + 'l' |
| 11 | +}) |
| 12 | + |
| 13 | +local args = utils.processArgs({...}, validArgs) |
| 14 | + |
| 15 | +if args.help then |
| 16 | + print( |
| 17 | +[[artifake.lua |
| 18 | +arguments: |
| 19 | + -help |
| 20 | + print this help message |
| 21 | + -material matstring |
| 22 | + specify the material of the item to be created |
| 23 | + examples: |
| 24 | + INORGANIC:IRON |
| 25 | + CREATURE_MAT:DWARF:BRAIN |
| 26 | + PLANT_MAT:MUSHROOM_HELMET_PLUMP:DRINK |
| 27 | +-item itemstring |
| 28 | + specify the itemdef of the item to be created |
| 29 | + examples: |
| 30 | + WEAPON:ITEM_WEAPON_PICK |
| 31 | +-name namestring |
| 32 | + specify a first name if desired |
| 33 | +-r |
| 34 | + for right handed gloves |
| 35 | +-l |
| 36 | + for left handed gloves |
| 37 | +]]) |
| 38 | + return |
| 39 | +end |
| 40 | + |
| 41 | +if dfhack.gui.getSelectedUnit(true) then |
| 42 | + args.creator = dfhack.gui.getSelectedUnit() |
| 43 | + else args.creator = df.global.world.units.active[0] |
| 44 | +end |
| 45 | +if not args.item then |
| 46 | + error 'Invalid item.' |
| 47 | +end |
| 48 | +local itemType = dfhack.items.findType(args.item) |
| 49 | +if itemType == -1 then |
| 50 | + error 'Invalid item.' |
| 51 | +end |
| 52 | +local itemSubtype = dfhack.items.findSubtype(args.item) |
| 53 | + |
| 54 | +args.material = dfhack.matinfo.find(args.material) |
| 55 | +if not args.material then |
| 56 | + error 'Invalid material.' |
| 57 | +end |
| 58 | + |
| 59 | + |
| 60 | +local item = dfhack.items.createItem(itemType, itemSubtype, args.material['type'], args.material.index, args.creator) |
| 61 | + |
| 62 | +local base=df.item.find(df.global.item_next_id-1) |
| 63 | +df.global.world.artifacts.all:new() |
| 64 | +df.global.world.artifacts.all:insert('#',{new=df.artifact_record}) |
| 65 | +local facts = df.global.world.artifacts.all |
| 66 | + for _,k in ipairs(facts) do |
| 67 | + if k.item==nil then |
| 68 | + local fake=k |
| 69 | + fake.id=df.global.artifact_next_id |
| 70 | + fake.item = {new=base} |
| 71 | + fake.item.flags.artifact = false |
| 72 | + fake.item.flags.artifact_mood = true |
| 73 | + fake.item.id = base.id |
| 74 | + fake.item.general_refs:insert('#',{new =df.general_ref_is_artifactst}) |
| 75 | + fake.item.general_refs[0].artifact_id = fake.id |
| 76 | + fake.item.spec_heat = base.spec_heat |
| 77 | + fake.item.ignite_point = base.ignite_point |
| 78 | + fake.item.heatdam_point = base.heatdam_point |
| 79 | + fake.item.colddam_point = base.colddam_point |
| 80 | + fake.item.boiling_point = base.boiling_point |
| 81 | + fake.item.fixed_temp = base.fixed_temp |
| 82 | + fake.item.weight = base.weight |
| 83 | + fake.item.weight_fraction = base.weight_fraction |
| 84 | + fake.item.improvements:insert('#',{new = df.itemimprovement_spikesst,mat_type=41,mat_index=3,quality=6,skill_rating=15}) |
| 85 | + fake.item.improvements:insert('#',{new = df.itemimprovement_spikesst,mat_type=40,mat_index=3,quality=6,skill_rating=15}) |
| 86 | + fake.item.improvements:insert('#',{new = df.itemimprovement_art_imagest,mat_type=43,mat_index=3,quality=6,skill_rating=15}) |
| 87 | + fake.item.improvements:insert('#',{new = df.itemimprovement_art_imagest,mat_type=420,mat_index=230,quality=6,skill_rating=15}) |
| 88 | + fake.item.improvements:insert('#',{new = df.itemimprovement_art_imagest,mat_type=0,mat_index=9,quality=6,skill_rating=15}) |
| 89 | + fake.flags:new() |
| 90 | + for i = 0,7 do |
| 91 | + if #fake.flags < 8 then |
| 92 | + fake.flags[i] = true |
| 93 | + elseif #fake.flags==8 then |
| 94 | + fake.flags[0] = false |
| 95 | + fake.flags[i] = false |
| 96 | + end |
| 97 | + end |
| 98 | + fake.anon_1 = -1000000 |
| 99 | + fake.anon_2 = -1000000 |
| 100 | + fake.anon_3 = -1000000 |
| 101 | + base.flags.artifact = false |
| 102 | + base.flags.artifact_mood = true |
| 103 | + base.general_refs = fake.item.general_refs |
| 104 | + base.improvements = fake.item.improvements |
| 105 | + fake.item:setQuality(6) |
| 106 | + base:setQuality(6) |
| 107 | + if (df.item_weaponst:is_instance(fake.item) or df.item_toolst:is_instance(fake.item)) then fake.item.sharpness=100000 end |
| 108 | + if (df.item_weaponst:is_instance(base) or df.item_toolst:is_instance(base)) then base.sharpness=100000 end |
| 109 | + df.global.artifact_next_id=df.global.artifact_next_id+1 |
| 110 | + df.global.world.history.events:new() |
| 111 | + df.global.world.history.events:insert('#',{new=df.history_event_artifact_createdst, |
| 112 | + year = df.global.cur_year, |
| 113 | + seconds = df.global.cur_year_tick_advmode, |
| 114 | + id = df.global.hist_event_next_id, |
| 115 | + artifact_id = fake.id, |
| 116 | + unit_id = args.creator.id, |
| 117 | + hfid = args.creator.hist_figure_id, |
| 118 | + } |
| 119 | + ) |
| 120 | + df.global.hist_event_next_id = df.global.hist_event_next_id+1 |
| 121 | +if args.r then |
| 122 | + base.handedness[0] = true |
| 123 | + fake.item.handedness[0] = true |
| 124 | +end |
| 125 | +if args.l then |
| 126 | + base.handedness[1] = true |
| 127 | + fake.item.handedness[1] = true |
| 128 | +end |
| 129 | + if args.name then do |
| 130 | +fake.name.first_name = args.name |
| 131 | +fake.name.language = 0 |
| 132 | +fake.name.has_name = true |
| 133 | + end |
| 134 | + end |
| 135 | + end |
| 136 | +end |
0 commit comments