Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

DeusEx.ComputerScreenHack


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
//=============================================================================
// ComputerScreenHack
//=============================================================================
class ComputerScreenHack extends HUDBaseWindow;

var PersonaNormalTextWindow   winDigits;
var PersonaHeaderTextWindow   winHackMessage;
var PersonaActionButtonWindow btnHack;
var ProgressBarWindow         barHackProgress;

var NetworkTerminal           winTerm;
var Float                     detectionTime;
var Float                     saveDetectionTime;
var Float                     hackTime;
var Float                     saveHackTime;
var Float                     blinkTimer;
var Float                     digitUpdateTimer;
var Float                     hackDetectedDelay;
var Bool                      bHacking;
var Bool                      bHacked;
var Bool                      bHackDetected;
var Bool                      bHackDetectedNotified;

var Int    digitWidth;
var String digitStrings[4];
var String digitFillerChars;
var Color  colDigits;
var Color  colRed;

// Defaults
var Texture texBackground;
var Texture texBorder;

// Text
var localized String HackButtonLabel;
var localized String ReturnButtonLabel;
var localized String HackReadyLabel;
var localized String HackInitializingLabel;
var localized String HackSuccessfulLabel;
var localized String HackDetectedLabel;
var localized String MPHackInitializingLabel;

// ----------------------------------------------------------------------
// InitWindow()
//
// Initialize the Window
// ----------------------------------------------------------------------

event InitWindow()
{
    Super.InitWindow();

    SetSize(215, 112);

    CreateControls();   

    SetHackMessage(HackReadyLabel);
}

// ----------------------------------------------------------------------
// DestroyWindow()
//
// Destroys the Window
// ----------------------------------------------------------------------

event DestroyWindow()
{
    if ((bHackDetected) && (!bHackDetectedNotified) && (winTerm != None))
        winTerm.HackDetected(True);

    Super.DestroyWindow();
}

// ----------------------------------------------------------------------
// CreateControls()
// ----------------------------------------------------------------------

function CreateControls()
{
    CreateTextDigits();
    CreateHackMessageWindow();
    CreateHackProgressBar();
    CreateHackButton(); 
}

// ----------------------------------------------------------------------
// CreateHackMessageWindow()
// ----------------------------------------------------------------------

function CreateHackMessageWindow()
{
    winHackMessage = PersonaHeaderTextWindow(NewChild(Class'PersonaHeaderTextWindow'));
    winHackMessage.SetPos(22, 19);
    winHackMessage.SetSize(168, 47);
    winHackMessage.SetTextAlignments(HALIGN_Center, VALIGN_Center);
    winHackMessage.SetBackgroundStyle(DSTY_Modulated);
    winHackMessage.SetBackground(Texture'HackInfoBackground');
}

// ----------------------------------------------------------------------
// CreateTextDigits()
// ----------------------------------------------------------------------

function CreateTextDigits()
{
    winDigits = PersonaNormalTextWindow(NewChild(Class'PersonaNormalTextWindow'));
    winDigits.SetPos(22, 19);
    winDigits.SetSize(168, 47);
    winDigits.SetFont(Font'FontFixedWidthSmall');
    winDigits.SetTextColor(colDigits);
    winDigits.SetTextAlignments(HALIGN_Left, VALIGN_Top);
    winDigits.SetTextMargins(0, 0);
}

// ----------------------------------------------------------------------
// CreateHackProgressBar()
// ----------------------------------------------------------------------

function CreateHackProgressBar()
{
    barHackProgress = ProgressBarWindow(NewChild(Class'ProgressBarWindow'));
    barHackProgress.SetPos(22, 71);
    barHackProgress.SetSize(169, 12);
    barHackProgress.SetValues(0, 100);
    barHackProgress.SetVertical(False);
    barHackProgress.UseScaledColor(True);
    barHackProgress.SetDrawBackground(False);
    barHackProgress.SetCurrentValue(100);
}

// ----------------------------------------------------------------------
// CreateHackButton()
// ----------------------------------------------------------------------

function CreateHackButton()
{
    local PersonaButtonBarWindow winActionButtons;

    winActionButtons = PersonaButtonBarWindow(NewChild(Class'PersonaButtonBarWindow'));
    winActionButtons.SetPos(20, 86);
    winActionButtons.SetWidth(88);
    winActionButtons.FillAllSpace(False);

    btnHack = PersonaActionButtonWindow(winActionButtons.NewChild(Class'PersonaActionButtonWindow'));
    btnHack.SetButtonText(HackButtonLabel);
}

// ----------------------------------------------------------------------
// DrawBackground()
// ----------------------------------------------------------------------

function DrawBackground(GC gc)
{
    gc.SetStyle(backgroundDrawStyle);
    gc.SetTileColor(colBackground);
    gc.DrawTexture(
        backgroundPosX, backgroundPosY, 
        backgroundWidth, backgroundHeight, 
        0, 0, texBackground);
}

// ----------------------------------------------------------------------
// DrawBorder()
// ----------------------------------------------------------------------

function DrawBorder(GC gc)
{
    if (bDrawBorder)
    {
        gc.SetStyle(borderDrawStyle);
        gc.SetTileColor(colBorder);
        gc.DrawTexture(0, 0, 221, 112, 0, 0, texBorder);
    }
}

// ----------------------------------------------------------------------
// SetNetworkTerminal()
// ----------------------------------------------------------------------

function SetNetworkTerminal(NetworkTerminal newTerm)
{
    winTerm = newTerm;
}

// ----------------------------------------------------------------------
// ButtonActivated()
// ----------------------------------------------------------------------

function bool ButtonActivated( Window buttonPressed )
{
    local bool bHandled;

    bHandled = True;

    switch( buttonPressed )
    {
        case btnHack:
            if (winTerm != None)
            {
                if (bHacked)
                    winTerm.ComputerHacked();
                else
                    StartHack();

                btnHack.SetSensitivity(False);
            }
            break;

        default:
            bHandled = False;
            break;
    }

    if (bHandled)
        return True;
    else
        return Super.ButtonActivated(buttonPressed);
}

// ----------------------------------------------------------------------
// StartHack()
// ----------------------------------------------------------------------

function StartHack()
{
    bHacking     = True;
    bTickEnabled = True;

    // Display hack message
   if (Player.Level.NetMode == NM_Standalone)   
      SetHackMessage(HackInitializingLabel);
   else
      SetHackMessage(MPHackInitializingLabel);
}

// ----------------------------------------------------------------------
// FinishHack()
// ----------------------------------------------------------------------

function FinishHack()
{
    bHacked = True;

    // Display hack message
    SetHackMessage(HackSuccessfulLabel);

    winDigits.SetText("");

    if (winTerm != None)
        winTerm.ComputerHacked();
}

// ----------------------------------------------------------------------
// HackDetected()
// ----------------------------------------------------------------------

function HackDetected()
{
    bHackDetected = True;
    blinkTimer    = Default.blinkTimer;
    detectionTime = hackDetectedDelay;
    bTickEnabled  = True;
    SetHackMessage(HackDetectedLabel);
    winHackMessage.SetTextColor(colRed);
}

// ----------------------------------------------------------------------
// SetHackMessage()
// ----------------------------------------------------------------------

function SetHackMessage(String newHackMessage)
{
    if (newHackMessage == "")
        winHackMessage.Hide();
    else
        winHackMessage.Show();

    winHackMessage.SetText(newHackMessage);
}

// ----------------------------------------------------------------------
// SetDetectionTime()
// ----------------------------------------------------------------------

function SetDetectionTime(Float newDetectionTime, Float newHackTime)
{
    // The detection time is how long it takes before the user is 
    // caught and electrified.  This now includes the Hack time to 
    // give the player the perception that he's being tracked 
    // immediately (a little more tense).  When in reality he has the 
    // same amount of "detection" time (once hacked) as before.

    detectionTime     = newDetectionTime + newHackTime;
    saveDetectionTime = detectionTime;

    // Hack time is also based on skill
    hackTime      = newHackTime;
    saveHackTime  = hackTime;
}

// ----------------------------------------------------------------------
// GetSaveDetectionTime()
// ----------------------------------------------------------------------

function Float GetSaveDetectionTime()
{
    return saveDetectionTime;
}

// ----------------------------------------------------------------------
// UpdateDetectionTime()
// ----------------------------------------------------------------------

function UpdateDetectionTime(Float newDetectionTime)
{
    detectionTime = newDetectionTime;

    // Update the progress bar
    UpdateHackBar();
}

// ----------------------------------------------------------------------
// UpdateDigits()
// ----------------------------------------------------------------------

function UpdateDigits()
{
    local bool bSpace;
    local int stringIndex;

    // First move down the existing strings

    for(stringIndex=arrayCount(digitStrings)-1; stringIndex>0;  stringIndex--)
        digitStrings[stringIndex] = digitStrings[stringIndex-1];
    
    // Now fill the string.  As we get closer to detection time, 
    // will fill with more characters
    
    digitStrings[0] = "";

    for(stringIndex=0; stringIndex<digitWidth; stringIndex++)
    {
        // Calculate chance that this is a space
        bSpace = ((saveHackTime - hackTime) / saveHackTime) > FRand();

        if (bSpace)
            digitStrings[0] = digitStrings[0] $ " ";
        else
            digitStrings[0] = digitStrings[0] $ Mid(digitFillerChars, Rand(Len(digitFillerChars)) + 1, 1);
    }

    winDigits.SetText("");

    for(stringIndex=0; stringIndex<arrayCount(digitStrings); stringIndex++)
    {
        winDigits.AppendText(digitStrings[stringIndex]);
        if (stringIndex - 1 == arrayCount(digitStrings))
            winDigits.AppendText("|n");
    }
}

// ----------------------------------------------------------------------
// UpdateHackBar()
// ----------------------------------------------------------------------

function UpdateHackBar()
{
    local float percentRemaining;

    percentRemaining = (detectionTime / saveDetectionTime) * 100;
    barHackProgress.SetCurrentValue(percentRemaining);
}

// ----------------------------------------------------------------------
// SetHackButtonToReturn()
// ----------------------------------------------------------------------

function SetHackButtonToReturn()
{
    btnHack.SetSensitivity(True);
    btnHack.SetButtonText(ReturnButtonLabel);
}

// ----------------------------------------------------------------------
// Tick()
// ----------------------------------------------------------------------

function Tick(float deltaTime)
{
    if (bHacking)   // manage initial hacking
    {
        hackTime         -= deltaTime;
        blinkTimer       -= deltaTime;
        digitUpdateTimer -= deltaTime;

        // Update blinking text
        if (blinkTimer < 0)
        {
            if (winHackMessage.GetText() == "")
            {
                blinkTimer = Default.blinkTimer;
            // Display hack message
            if (Player.Level.NetMode == NM_Standalone)  
               SetHackMessage(HackInitializingLabel);
            else
               SetHackMessage(MPHackInitializingLabel);
            }
            else
            {
                blinkTimer = Default.blinkTimer / 3;
                winHackMessage.SetText("");
            }
        }

        // Update scrolling text
        if (digitUpdateTimer < 0)
        {
            digitUpdateTimer = Default.digitUpdateTimer;
            UpdateDigits();
        }

        if (hackTime < 0)
        {
            bHacking = False;
            FinishHack();
        }   
    }
    
    if (bHackDetected)
    {
        detectionTime -= deltaTime;
        blinkTimer    -= deltaTime;

        // Update blinking text
        if (blinkTimer < 0)
        {
            if (winHackMessage.GetText() == "")
            {
                blinkTimer = Default.blinkTimer;
                winHackMessage.SetText(HackDetectedLabel);
            }
            else
            {
                blinkTimer = Default.blinkTimer / 3;
                winHackMessage.SetText("");
            }
        }

        if (detectionTime < 0)
        {
            if (winTerm != None)
            {
                bHackDetectedNotified = True;
                winTerm.HackDetected();
            }
        }
    }
    else
    {
        // manage detection
        detectionTime -= deltaTime;

        // Update the progress bar
        UpdateHackBar();

        if (detectionTime < 0)
        {
            detectionTime = 0;
            bTickEnabled = False;
            HackDetected();
        }
    }
}

// ----------------------------------------------------------------------
// VirtualKeyPressed()
//
// Called when a key is pressed; provides a virtual key value
// ----------------------------------------------------------------------

event bool VirtualKeyPressed(EInputKey key, bool bRepeat)
{
    local bool bKeyHandled;
    bKeyHandled = True;

    switch( key ) 
    {   
        case IK_Escape:
            winTerm.ForceCloseScreen(); 
            break;

        default:
            bKeyHandled = False;
    }

    if (bKeyHandled)
        return True;
    else
        return Super.VirtualKeyPressed(key, bRepeat);
}

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

defaultproperties
{
     blinkTimer=1.000000
     digitUpdateTimer=0.050000
     hackDetectedDelay=3.000000
     digitWidth=23
     digitFillerChars="01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()_+-=][}{"
     colDigits=(G=128)
     colRed=(R=255)
     texBackground=Texture'DeusExUI.UserInterface.ComputerHackBackground'
     texBorder=Texture'DeusExUI.UserInterface.ComputerHackBorder'
     HackButtonLabel="|&Hack"
     ReturnButtonLabel="|&Return"
     HackReadyLabel="Ice Breaker Ready..."
     HackInitializingLabel="Initializing ICE Breaker..."
     HackSuccessfulLabel="ICE Breaker Hack Successful..."
     HackDetectedLabel="*** WARNING ***|nINTRUDER DETECTED!"
     MPHackInitializingLabel="Hacking... Hit ESC to Abort"
     backgroundWidth=187
     backgroundHeight=94
     backgroundPosX=14
     backgroundPosY=13
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Mon 8/11/2021 16:22:50.000 - Creation time: Mon 8/11/2021 16:31:24.277 - Created with UnCodeX