(version 2)
(include "sci.sh")
(exports
    0 egoMonster
)
(use "Main")
(use "CombatIcon")
(use "Cycle")
(use "View")
(use "Obj")
(script 860)



(procedure (localproc_0040)
    (if (>= gGOwnerMaxStamina[16] 55)
        (send gWarriorObj:getHurt(30))
    )(else
        (if (not (send gGQg3KDHandler:contains(haramiMan)))
            (haramiMan:init())
        )
    )
)


(instance public egoMonster of Monster
    (properties
        x 174
        y 136
        roar 901
        secDamage 30
        armorValue 10
        spellHitX 164
        spellHitY 96
        mustFight 1
    )

    (method (init param1)
        (send global2:picture(0))
        (self:
            primDamage(* (send gWarriorObj:weapValue) 2)
            monHP(gGOwnerMaxStamina[16])
            view(
                (if ((send gOwner:has(1)))
                    844
                )(else
                    843
                )
)
        )
        (super:init(rest param1))
        (self:setScript(sFight))
        (send gLongSong:
            setLoop(-1)
            changeTo(845)
        )
    )


    (method (getHurt)
        (self:setScript(sReact))
        (if (> (- gGMonsterMonHP gGOwnerMaxStamina[16]) 60)
            = gGMonsterMonHP (- gGMonsterMonHP 5)
        )(else
            (if (> (- gGMonsterMonHP gGOwnerMaxStamina[16]) 30)
                = gGMonsterMonHP (- gGMonsterMonHP 2)
            )
        )
        (send (ScriptID(550 3)):update())
    )


    (method (defenseLevel)
        return 250
    )

)
(instance sFight of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = ticks (/ Random(45 180) global209)
            )
            (case 1
                (self:start(1))
                (if (== gCalledBy 1)
                    (send client:setScript(sCast))
                )(else
                    (send gMonster:
                        setLoop(
                            (if ((send gOwner:has(1)))
                                Random(0 2)
                            )(else
                                0
                            )
)
                        setCycle(End self)
                    )
                )
            )
            (case 2
                (if (not 
                (if ((== (send gWarriorObj:view) 26) or (== (send gWarriorObj:view) 27))
                )(else
                    == (send gWarriorObj:view) 555
                )
)
                    localproc_0040((send gMonster:primDamage))
                )(else
                    (send gLongSong2:
                        number(940)
                        play()
                    )
                )
                = cycles (+ (/ 3 global209) 1)
            )
            (case 3
                (send gMonster:
                    setLoop(0)
                    setCel(0)
                    stopUpd()
                )
                = ticks (/ Random(45 180) global209)
            )
            (case 4
                (self:init())
            )
        )
    )

)
(instance sCast of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gMonster:
                    setLoop(1)
                    setCel(0)
                    setCycle(End self)
                )
            )
            (case 1
                (monSpell:
                    setLoop(
                        (switch ((send (ScriptID(550 2)):approachDist))
                            (case 27
                                1
                            )
                            (case 32
                                2
                            )
                            (default 
                                0
                            )
                        )
)
                    init()
                    x(180)
                    y(100)
                    setMotion(MoveTo (send gWarriorObj:x) - (send gWarriorObj:y) 45 monSpell)
                )
                (send gLongSong2:
                    number(
                        (switch ((send (ScriptID(550 2)):approachDist))
                            (case 27
                                11
                            )
                            (case 32
                                11
                            )
                            (default 
                                13
                            )
                        )
)
                    play()
                )
                = ticks (/ Random(45 180) global209)
            )
            (case 2
                (if (== gCalledBy 1)
                    (self:init())
                )(else
                    (send client:setScript(sFight))
                )
            )
        )
    )

)
(instance sReact of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gMonster:
                    setLoop(0)
                    setCel(2)
                )
                = ticks 60
            )
            (case 1
                (send gMonster:whimper())
                = ticks (- (/ Random(45 180) global209) 14)
            )
            (case 2
                (if (== gCalledBy 1)
                    (send gMonster:setScript(sCast))
                )(else
                    (send gMonster:setScript(sFight))
                )
            )
        )
    )

)
(instance monSpell of Actor
    (properties
        x 180
        y 100
        yStep 15
        view 22
        priority 11
        signal $4810
        cycleSpeed 5
        xStep 15
        moveSpeed 0
    )

    (method (cue)
        (var temp0)
        (if ((< loop 3) and (> x 10))
            (if (not 
            (if ((== (send gWarriorObj:view) 26) or (== (send gWarriorObj:view) 27))
            )(else
                == (send gWarriorObj:view) 555
            )
)
                = temp0 0
                (switch ((send (ScriptID(550 2)):approachDist))
                    (case 27
                        = temp0 (* (+ 10 (/ gGOwnerMaxStamina[27] 20)) 2)
                    )
                    (case 32
                        = temp0 (* (+ 12 (/ gGOwnerMaxStamina[32] 20)) 2)
                    )
                    (default 
                        = temp0 (* (+ 10 (/ gGOwnerMaxStamina[25] 20)) 2)
                    )
                )
                localproc_0040(temp0)
                (send gLongSong2:
                    number(930)
                    play()
                )
                (self:
                    setCel(0)
                    setLoop(+ loop 3)
                    setCycle(End self)
                )
            )(else
                (self:setMotion(MoveTo -30 y self))
            )
        )(else
            (self:dispose())
        )
    )

)
(instance haramiMan of Actor
    (properties
        x 245
        y 66
        view 847
        signal $4010
        cycleSpeed 40
        xStep 1
        moveSpeed 4
    )

    (method (init param1)
        (super:init(rest param1))
        (self:setCycle(CT 1 1 self))
    )


    (method (cue)
        (if (not loop)
            (switch (cel)
                (case 1
                    (self:
                        setMotion(MoveTo - x 10 y)
                        setCycle(CT 2 1 self)
                    )
                )
                (case 2
                    (self:
                        setMotion(MoveTo - x 10 y)
                        setCycle(CT 3 1 self)
                    )
                )
                (case 3
                    (self:
                        setMotion(MoveTo - x 10 y)
                        setCycle(CT 4 1 self)
                    )
                )
                (case 4
                    (self:
                        setLoop(1)
                        setCel(0)
                        cycleSpeed(6)
                        setCycle(End self)
                    )
                )
            )
        )(else
            (send gMonster:
                setCycle(0)
                setScript(0)
            )
            proc0_2()
            (send gWarriorObj:
                setCycle(0)
                setScript(sMonsterDie)
            )
        )
    )

)
(instance sMonsterDie of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = ticks 40
            )
            (case 1
                = gGMonsterMonHP 0
                = global155 -1
                (send (ScriptID(550 3)):cue())
            )
        )
    )

)
