unit ObjectTrap;

interface

uses
  CustomObject, Vec2f, System.SysUtils, IniFiles, Collision;

type
  TObjectTrap = class(TCustomObject)
  private
    FRadius: Single;
    FDamage: Integer;
  public
    procedure Draw; override;
    procedure SetActive(AAction: Boolean); override;
  published
    procedure Load(Aini: TIniFile); override;
  end;

implementation

uses
  Resources, Units.Custom, Units.Player, GameOverlay;

procedure TObjectTrap.Load(Aini: TIniFile);
var
  Str: String;
begin
  inherited;
  Str := 'Obj_' + IntToStr(ID);
  FRadius := Aini.ReadFloat(Str, 'Radius', 12);
  FDamage := Aini.ReadInteger(Str, 'Damage', 50);
end;

procedure TObjectTrap.SetActive(AAction: Boolean);
var
  i: Integer;
  Rect: T2DRect;
begin
  inherited;
  if not AAction then
    Exit;

  Rect.Size := TVec2f.Create(FRadius, FRadius) * 2;
  Rect.Position := Position - Rect.Size / 2;
  for i := 0 to TGlobals.LevelHeroes.Count - 1 do
    if TCollision.PointRect(TGlobals.LevelHeroes[i].Position, Rect) then
    begin
      TGlobals.LevelHeroes[i].Damage(FDamage);
      if (TGlobals.LevelHeroes[i].HP > 0) and (Random(100) < 5) then
        case TGlobals.LevelHeroes[i].Sex of
          stMale:
            case random(2) of
              0: TGameOverlay.AddDialog(TGlobals.LevelHeroes[i].Portrait, 'Òåïåðü ñêâîçü äûðêè â øòàíàõ, âèäíî ìîè áóáåíöû', lEarth);
              1: TGameOverlay.AddDialog(TGlobals.LevelHeroes[i].Portrait, 'Ôóõ, îíè ÷óòü íå ïîðåçàëè ìîþ ìàøåíêó!', lEarth);
            end;
          stFemale:
            case random(2) of
              0: TGameOverlay.AddDialog(TGlobals.LevelHeroes[i].Portrait, 'ÁËÅÀÒÜ, ÝÒÎ ÆÅ ÁÛËÈ ÍÎÂÛÅ ÒÐÓÑÅËß!!!', lEarth);
              1: TGameOverlay.AddDialog(TGlobals.LevelHeroes[i].Portrait, 'Áûë ó ìåíÿ îäèí ìóæèê, îí äåëàë òàê æå çóáàìè', lEarth);
            end;
        end;
    end;
end;

procedure TObjectTrap.Draw;
begin
  if FAction then
    TGlobals.QuadRender.Rectangle(Position - TVec2f.Create(FRadius, FRadius), Position + TVec2f.Create(FRadius, FRadius), $FF00FF00)
  else
    TGlobals.QuadRender.Rectangle(Position - TVec2f.Create(FRadius, FRadius), Position + TVec2f.Create(FRadius, FRadius), $FFFF0000);
end;


end.
