Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local assets =
- {
- Asset("ANIM", "anim/shop_basic.zip"),
- Asset("ATLAS", "minimap/shopkeeper.xml"),
- Asset("IMAGE", "minimap/shopkeeper.tex"),
- }
- local prefabs =
- {
- "tentacle_pillar_arm",
- "armormarble",
- "armor_sanity",
- "armorsnurtleshell",
- "resurrectionstatue",
- "poop",
- "stafflight",
- "firemerm",
- "collapse_small",
- }
- local spawns =
- {
- armor_sanity = 0.5,
- health_plus = 10,
- health_minus = 10,
- stafflight = 15,
- poop = 50,
- firemerm = 200,
- trinket = 75,
- }
- local actions =
- {
- trinket = { amt = 2, },
- poop = { amt = 5, },
- firemerm = { amt = 3, },
- stafflight = { amt = 1, },
- }
- local MAX_LIGHT_ON_FRAME = 15
- local MAX_LIGHT_OFF_FRAME = 30
- local function OnLightDirty(inst)
- if inst._lighttask == nil then
- inst._lighttask = inst:DoPeriodicTask(FRAMES, OnUpdateLight, nil, 1)
- end
- inst._lightmaxframe = inst._islighton:value() and MAX_LIGHT_ON_FRAME or MAX_LIGHT_OFF_FRAME
- OnUpdateLight(inst, 0)
- end
- local function PlayerSpawnCritter(player, critter, pos)
- TheWorld:PushEvent("ms_sendlightningstrike", pos)
- SpawnPrefab("collapse_small").Transform:SetPosition(pos:Get())
- local spawn = SpawnPrefab(critter)
- if spawn ~= nil then
- spawn.Transform:SetPosition(pos:Get())
- if spawn.components.combat ~= nil then
- spawn.components.combat:SetTarget(player)
- end
- end
- end
- local function SpawnCritter(critter, pos, player)
- player:DoTaskInTime(GetRandomWithVariance(1, 0.8), PlayerSpawnCritter, critter, pos)
- end
- local function SpawnAt(inst, prefab)
- local pos = inst:GetPosition()
- local offset, check_angle, deflected = FindWalkableOffset(pos, math.random() * 2 * PI, 4 , 8, true, false) -- try to avoid walls
- if offset ~= nil then
- return SpawnPrefab(prefab).Transform:SetPosition((pos + offset):Get())
- end
- end
- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- local function DoRandomThing(inst, pos, count, target)
- count = count or 1
- pos = pos or inst:GetPosition()
- for doit = 1, count do
- local item = weighted_random_choice(spawns)
- local doaction = actions[item]
- local amt = doaction ~= nil and doaction.amt or 1
- local sanity = doaction ~= nil and doaction.sanity or 0
- local health = doaction ~= nil and doaction.health or 0
- local func = doaction ~= nil and doaction.callback or nil
- local radius = doaction ~= nil and doaction.radius or 4
- local player = target
- if doaction ~= nil and doaction.var ~= nil then
- amt = math.max(0, GetRandomWithVariance(amt, doaction.var))
- end
- if amt == 0 and func ~= nil then
- func(inst, item, doaction)
- end
- for i = 1, amt do
- local offset, check_angle, deflected = FindWalkableOffset(pos, math.random() * 2 * PI, radius , 8, true, false) -- try to avoid walls
- if offset ~= nil then
- if func ~= nil then
- func(inst, item, doaction)
- elseif item == "trinket" then
- local prefab = PickRandomTrinket()
- if prefab ~= nil then
- SpawnCritter(prefab, pos + offset, player)
- end
- else
- SpawnCritter(item, pos + offset, player)
- end
- end
- end
- end
- end
- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- local function OnIsNight(inst, isnight)
- if isnight then
- inst.components.trader:Disable()
- inst.AnimState:PlayAnimation("night_pre")
- inst.AnimState:PushAnimation("idle_night", true)
- else
- inst.components.trader:Enable()
- inst.AnimState:PlayAnimation("night_pst")
- inst.AnimState:PushAnimation("idle", true)
- end
- end
- local function OnTurnOn(inst, isnight)
- if inst.components.talker then
- inst.components.talker:Say(TUNING.CLOSETEXT)
- inst.SoundEmitter:PlaySound("dontstarve/maxwell/talk_LP_world6", "talk")
- inst:DoTaskInTime(2, function(inst)
- inst.SoundEmitter:KillSound("talk")
- end)
- end
- end
- local function OnTurnOff(inst, isnight)
- if inst.components.talker then
- inst.components.talker:Say(TUNING.GONETEXT)
- inst.SoundEmitter:PlaySound("dontstarve/maxwell/talk_LP_world6", "talk")
- inst:DoTaskInTime(2, function(inst)
- inst.SoundEmitter:KillSound("talk")
- end)
- end
- end
- local function onactivate(inst)
- inst.AnimState:PlayAnimation("purchase")
- inst.AnimState:PushAnimation("idle", true)
- inst.SoundEmitter:PlaySound("dontstarve/common/teleportato/teleportato_maxwelllaugh")
- if inst.components.talker then
- inst.components.talker:Say(TUNING.BUYTEXT)
- end
- end
- local function ShouldAcceptItem(inst, item)
- if item.prefab == ("firescale") then
- return true
- else
- return false
- end
- end
- local function OnGetItemFromPlayer(inst, giver, item)
- local pos = inst:GetPosition()
- if item.prefab == ("firescale") then
- if inst.components.talker then
- inst.components.talker:Say("SUKKKKK")
- inst.SoundEmitter:PlaySound("dontstarve/characters/skincollector/talk_LP", "skincollector")
- inst:DoTaskInTime(2, function(inst)
- inst.SoundEmitter:KillSound("skincollector")
- inst.AnimState:PlayAnimation("spawnshit")
- inst.AnimState:PushAnimation("idle", true)
- inst:DoTaskInTime(1, function(inst)
- inst.SoundEmitter:PlaySound("dontstarve/rain/thunder_close")
- inst:DoTaskInTime(1, DoRandomThing(inst, pos, nil, giver))
- end)
- end)
- end
- end
- end
- local function fn()
- local inst = CreateEntity()
- inst.entity:AddTransform()
- inst.entity:AddAnimState()
- inst.entity:AddSoundEmitter()
- inst.entity:AddNetwork()
- inst.AnimState:SetBank("shop")
- inst.AnimState:SetBuild("shop_basic")
- inst.AnimState:PlayAnimation("idle", true)
- inst:AddTag("trader")
- inst:AddComponent("trader")
- inst.components.trader:SetAcceptTest(ShouldAcceptItem)
- inst.components.trader.onaccept = OnGetItemFromPlayer
- inst:AddTag("prototyper")
- inst:AddTag("structure")
- MakeObstaclePhysics(inst, .4)
- local minimap = inst.entity:AddMiniMapEntity()
- minimap:SetIcon( "shopkeeper.tex" )
- inst.entity:SetPristine()
- if not TheWorld.ismastersim then
- return inst
- end
- inst:AddComponent("inspectable")
- inst:AddComponent("talker")
- inst.components.talker.fontsize = 35
- inst.components.talker.font = TALKINGFONT
- inst.components.talker.offset = Vector3(0,-575,0)
- inst:AddComponent("prototyper")
- inst.components.prototyper.trees = TUNING.PROTOTYPER_TREES.SHOP_ONE
- inst.components.prototyper.onturnon = OnTurnOn
- inst.components.prototyper.onturnoff = OnTurnOff
- inst.components.prototyper.onactivate = onactivate
- inst:AddComponent("wardrobe")
- inst.components.wardrobe:SetCanUseAction(false) --also means NO wardrobe tag!
- inst.components.wardrobe:SetCanBeShared(true)
- inst.components.wardrobe:SetRange(TUNING.RESEARCH_MACHINE_DIST + 1)
- inst:AddComponent("hauntable")
- inst.components.hauntable:SetHauntValue(TUNING.HAUNT_TINY)
- inst:WatchWorldState("isnight", OnIsNight)
- OnIsNight(inst, TheWorld.state.isnight)
- return inst
- end
- return Prefab( "common/objects/hum_shop", fn, assets, prefabs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement