-- This plugin is the combination of:
-- NoPiD, by Treellama
-- M1 Soft Deaths v1.0, by Hopper

Triggers = {}

function skip_pid()
   destination = Polygons[56]
   for p in Players() do
      p:position(destination.x, destination.y, destination.z, destination.index)
      p.direction = -40
   end     
end

function idle_once()
   skip_pid()
   Triggers.idle = nil
end

-- remember weaknesses we turned off to enable soft deaths
manual_weaknesses = {}

function soft_death_damage(t)
  if t == "explosion" then return false end
  if t == "crushing"  then return false end
  if t == "lava"      then return false end
  return true
end

function Triggers.init()
  -- No PiD opening
  if Level.name == "Arrival" then
    Triggers.idle = idle_once
  end
  
  -- just one fist
  for p in Players() do
    if p.items["knife"] > 1 then
      p.items["knife"] = 1
    end
  end
  
  -- soft deaths for BoBs
  for t in DamageTypes() do
    if soft_death_damage(t) then
      manual_weaknesses[t] = {}
      for m in MonsterTypes() do
        if m.weaknesses[t] then
          -- disable weakness to fix shapes, but remember
          -- it to apply double damage later
          manual_weaknesses[t][m] = true
          m.weaknesses[t] = false
        end
      end
    end
  end
end

function Triggers.monster_damaged(monster, aggressor, damage_type, damage_amount, projectile)
  if manual_weaknesses[damage_type] and manual_weaknesses[damage_type][monster.type] then
    -- apply double damage manually, by subtracting damage again
    monster.vitality = monster.vitality - damage_amount
  end
end
