public TriggerComponent(Item item, XElement element) : base(item, element)
        {
            string triggeredByAttribute = element.GetAttributeString("triggeredby", "Character");

            if (!Enum.TryParse(triggeredByAttribute, out triggeredBy))
            {
                DebugConsole.ThrowError($"Error in ForceComponent config: \"{triggeredByAttribute}\" is not a valid triggerer type.");
            }
            triggerOnce = element.GetAttributeBool("triggeronce", false);
            string parentDebugName = $"TriggerComponent in {item.Name}";

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "statuseffect":
                    LevelTrigger.LoadStatusEffect(statusEffects, subElement, parentDebugName);
                    break;

                case "attack":
                case "damage":
                    LevelTrigger.LoadAttack(subElement, parentDebugName, triggerOnce, attacks);
                    break;
                }
            }
            IsActive = true;
        }
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
 }
Exemple #3
0
 private void Update()
 {
     //    Debug.Log("We are in room " + currentRoom.name);
     if (isInRoom())
     {
         currentRoom = this;
     }
 }
Exemple #4
0
    public void animate_level_load_in(LevelTrigger levelTrigger)
    {
        // Set our level trigger
        this.currentLevelTrigger = levelTrigger;

        // Animate the fade in
        this.animator.SetTrigger(this.animFadeIn);
    }
        public override void Update(float deltaTime, Camera cam)
        {
            triggerers.RemoveWhere(t => t.Removed);
            LevelTrigger.RemoveDistantTriggerers(PhysicsBody, triggerers, item.WorldPosition);

            if (triggerOnce)
            {
                if (TriggeredOnce)
                {
                    return;
                }
                if (triggerers.Count > 0)
                {
                    TriggeredOnce = true;
                    IsActive      = false;
                    triggerers.Clear();
                }
            }

            TriggerActive = triggerers.Any();

            foreach (Entity triggerer in triggerers)
            {
                LevelTrigger.ApplyStatusEffects(statusEffects, item.WorldPosition, triggerer, deltaTime, statusEffectTargets);

                if (triggerer is IDamageable damageable)
                {
                    LevelTrigger.ApplyAttacks(attacks, damageable, item.WorldPosition, deltaTime);
                }
                else if (triggerer is Submarine submarine)
                {
                    LevelTrigger.ApplyAttacks(attacks, item.WorldPosition, deltaTime);
                }

                if (Force < 0.01f)
                {
                    // Just ignore very minimal forces
                    continue;
                }
                else if (triggerer is Character c)
                {
                    ApplyForce(c.AnimController.Collider);
                }
                else if (triggerer is Submarine s)
                {
                    ApplyForce(s.SubBody.Body);
                }
                else if (triggerer is Item i && i.body != null)
                {
                    ApplyForce(i.body);
                }
            }

            item.SendSignal(IsActive ? "1" : "0", "state_out");
        }
Exemple #6
0
    public void EnterNextStage(LevelTrigger t)
    {
        if (t.nextStage == null)
        {
            Debug.LogWarning("No next stage, ending");
            return;
        }
        lastStage = stage;
        Destroy(lastStage.gameObject);

        stage = Instantiate(t.nextStage, Vector3.zero, Quaternion.identity);
    }
 private bool OnCollision(Fixture sender, Fixture other, Contact contact)
 {
     if (!(LevelTrigger.GetEntity(other) is Entity entity))
     {
         return(false);
     }
     if (!LevelTrigger.IsTriggeredByEntity(entity, triggeredBy, mustBeOnSpecificSub: (true, item.Submarine)))
     {
         return(false);
     }
     triggerers.Add(entity);
     return(true);
 }
Exemple #8
0
        /// <summary>
        /// Configures the main scope screen viewmodel.
        /// </summary>
        private void ConfigureMainScopeScreenVM(IScopeScreenViewModel scopeScreenVM,
                                                IEnumerable <SampleSequence> sampleSequences)
        {
            // === Channels configuration ===

            var timeScaleFactor = 1;
            var channelVMs      = new[]
            {
                new ChannelViewModel("V", new Position(0, 1), timeScaleFactor, 1,
                                     BuildChannelCaptionFromIndex(0), _channelColors[0]),
                new ChannelViewModel("V", new Position(0, -2), timeScaleFactor, 1,
                                     BuildChannelCaptionFromIndex(1), _channelColors[1]),
            };

            var index = 0;

            channelVMs[index].MeasurementCursor1VM.Visible = true;
            channelVMs[index].MeasurementCursor2VM.Visible = true;
            channelVMs[index].MeasurementCursor1VM.Value   = 2.0;
            channelVMs[index].MeasurementCursor2VM.Value   = 3.0;
            //            index++;
            //            channelVMs[index].MeasurementCursor1VM.Visible = true;
            //            channelVMs[index].MeasurementCursor2VM.Visible = true;
            //            channelVMs[index].MeasurementCursor1VM.Value = -0.5;
            //            channelVMs[index].MeasurementCursor2VM.Value = 0.5;
            scopeScreenVM.ChannelVMs = channelVMs;

            // === Graphbase configuration ===

            var graphbaseVM = new GraphbaseViewModel("s", 1, _baseColor);

            var trigger             = new LevelTrigger(LevelTriggerMode.RisingEdge, 0.5);
            var triggerChannelIndex = 0;

            graphbaseVM.TriggerVM =
                new LevelTriggerViewModel(trigger, channelVMs[triggerChannelIndex]);
            graphbaseVM.MeasurementCursor1VM.Visible = true;
            graphbaseVM.MeasurementCursor2VM.Visible = true;
            graphbaseVM.MeasurementCursor1VM.Value   = 2.0;
            graphbaseVM.MeasurementCursor2VM.Value   = 3.0;
            scopeScreenVM.GraphbaseVM = graphbaseVM;

            // === Sample Sequences ===

            var sampleSequenceProviders =
                sampleSequences.Select(ss => new Func <SampleSequence>(() => ss));

            var sampler = new Sampler(sampleSequenceProviders, trigger, triggerChannelIndex);

            scopeScreenVM.SampleSequenceProviders = sampler.SampleSequenceProviders;
        }
Exemple #9
0
    // Start is called before the first frame update
    void Awake()
    {
        //startTime = Time.time;
        timerText      = this.GetComponent <Text>();
        isTimerWorking = true;
        //ExtraTime(10);

        try
        {
            npc          = GameObject.FindGameObjectWithTag("redNPC").transform;
            levelTrigger = GameObject.FindGameObjectWithTag("levelTrigger").GetComponent <LevelTrigger>();
        }
        catch

        { }
    }
 private void OnSeparation(Fixture sender, Fixture other, Contact contact)
 {
     if (!(LevelTrigger.GetEntity(other) is Entity entity))
     {
         return;
     }
     if (entity is Character character && (!character.Enabled || character.Removed) && triggerers.Contains(entity))
     {
         triggerers.Remove(entity);
         return;
     }
     if (LevelTrigger.CheckContactsForOtherFixtures(PhysicsBody, other, entity))
     {
         return;
     }
     triggerers.Remove(entity);
 }
        public override void OnItemLoaded()
        {
            base.OnItemLoaded();
            float radiusAttribute = originalElement.GetAttributeFloat("radius", 10.0f);

            Radius      = ConvertUnits.ToSimUnits(radiusAttribute * item.Scale);
            PhysicsBody = new PhysicsBody(0.0f, 0.0f, Radius, 1.5f)
            {
                BodyType            = BodyType.Static,
                CollidesWith        = LevelTrigger.GetCollisionCategories(triggeredBy),
                CollisionCategories = Physics.CollisionWall,
                UserData            = item
            };
            PhysicsBody.FarseerBody.SetIsSensor(true);
            PhysicsBody.FarseerBody.OnCollision  += OnCollision;
            PhysicsBody.FarseerBody.OnSeparation += OnSeparation;
            RadiusInDisplayUnits = ConvertUnits.ToDisplayUnits(PhysicsBody.radius);
        }
        private void ApplyForce(PhysicsBody body)
        {
            Vector2 diff = ConvertUnits.ToDisplayUnits(PhysicsBody.SimPosition - body.SimPosition);

            if (diff.LengthSquared() < 0.0001f)
            {
                return;
            }
            float distanceFactor = LevelTrigger.GetDistanceFactor(body, PhysicsBody, RadiusInDisplayUnits);

            if (distanceFactor <= 0.0f)
            {
                return;
            }
            Vector2 force = distanceFactor * Force * Vector2.Normalize(diff);

            if (force.LengthSquared() < 0.01f)
            {
                return;
            }
            body.ApplyForce(force);
        }
Exemple #13
0
    public void Start()
    {
        player = FindObjectOfType <Player>();
        if (player == null)
        {
            player = Instantiate(playerPrefab, playerStartPoint.position, Quaternion.identity);
        }
        else
        {
            player.transform.position = playerStartPoint.position;
        }

        luggage = FindObjectOfType <Luggage>();
        if (luggage == null)
        {
            luggage = Instantiate(luggagePrefab, luggageStartPoint.position, Quaternion.identity);
        }
        else
        {
            luggage.transform.position = luggageStartPoint.position;
        }

        levelTrigger = GetComponentInChildren <LevelTrigger>();
    }
	void Awake ()
    {
        _levelTriggerRef = transform.parent.GetComponent<LevelTrigger>();
	}
Exemple #15
0
        public override void UpdateHUD(Character character, float deltaTime, Camera cam)
        {
            if (unsentChanges)
            {
                if (networkUpdateTimer <= 0.0f)
                {
#if CLIENT
                    if (GameMain.Client != null)
                    {
                        item.CreateClientEvent(this);
                        correctionTimer = CorrectionDelay;
                    }
#endif
                    if (GameMain.Server != null)
                    {
                        item.CreateServerEvent(this);
                    }

                    networkUpdateTimer = 0.1f;
                    unsentChanges      = false;
                }
            }
            networkUpdateTimer -= deltaTime;

            if (sonarView.Rect.Contains(PlayerInput.MousePosition))
            {
                float scrollSpeed = PlayerInput.ScrollWheelSpeed / 1000.0f;
                if (Math.Abs(scrollSpeed) > 0.0001f)
                {
                    zoomSlider.BarScroll += PlayerInput.ScrollWheelSpeed / 1000.0f;
                    zoomSlider.OnMoved(zoomSlider, zoomSlider.BarScroll);
                }
            }

            float distort = 1.0f - item.Condition / 100.0f;
            for (int i = sonarBlips.Count - 1; i >= 0; i--)
            {
                sonarBlips[i].FadeTimer -= deltaTime * MathHelper.Lerp(0.5f, 2.0f, distort);
                sonarBlips[i].Position  += sonarBlips[i].Velocity * deltaTime;

                if (sonarBlips[i].FadeTimer <= 0.0f)
                {
                    sonarBlips.RemoveAt(i);
                }
            }

            foreach (GUIComponent component in activeControlsContainer.Parent.GetAllChildren())
            {
                if (component is GUITextBlock textBlock)
                {
                    textBlock.TextColor = IsActive ? textBlock.Style.textColor : textBlock.Style.textColor * 0.5f;
                }
            }

            //sonar view can only get focus when the cursor is inside the circle
            sonarView.CanBeFocused =
                Vector2.DistanceSquared(sonarView.Rect.Center.ToVector2(), PlayerInput.MousePosition) <
                (sonarView.Rect.Width / 2 * sonarView.Rect.Width / 2);

            if (UseTransducers && connectedTransducers.Count == 0)
            {
                return;
            }

            Vector2 transducerCenter = UseTransducers ? GetTransducerCenter() : item.WorldPosition;
            transducerCenter += DisplayOffset;

            if (Level.Loaded != null)
            {
                Dictionary <LevelTrigger, Vector2> levelTriggerFlows = new Dictionary <LevelTrigger, Vector2>();
                foreach (LevelObject levelObject in Level.Loaded.LevelObjectManager.GetAllObjects(transducerCenter, range * pingState / zoom))
                {
                    //gather all nearby triggers that are causing the water to flow into the dictionary
                    foreach (LevelTrigger trigger in levelObject.Triggers)
                    {
                        Vector2 flow = trigger.GetWaterFlowVelocity();
                        //ignore ones that are barely doing anything (flow^2 < 1)
                        if (flow.LengthSquared() > 1.0f)
                        {
                            levelTriggerFlows.Add(trigger, flow);
                        }
                    }
                }

                foreach (KeyValuePair <LevelTrigger, Vector2> triggerFlow in levelTriggerFlows)
                {
                    LevelTrigger trigger = triggerFlow.Key;
                    Vector2      flow    = triggerFlow.Value;

                    float flowMagnitude = flow.Length();
                    if (Rand.Range(0.0f, 1.0f) < flowMagnitude / 1000.0f)
                    {
                        float   edgeDist = Rand.Range(0.0f, 1.0f);
                        Vector2 blipPos  = trigger.WorldPosition + Rand.Vector(trigger.ColliderRadius * edgeDist);
                        Vector2 blipVel  = flow;
                        if (trigger.ForceFalloff)
                        {
                            flow *= (1.0f - edgeDist);
                        }

                        //go through other triggers in range and add the flows of the ones that the blip is inside
                        foreach (KeyValuePair <LevelTrigger, Vector2> triggerFlow2 in levelTriggerFlows)
                        {
                            LevelTrigger trigger2 = triggerFlow2.Key;
                            if (trigger2 != trigger && Vector2.DistanceSquared(blipPos, trigger2.WorldPosition) < trigger2.ColliderRadius * trigger2.ColliderRadius)
                            {
                                Vector2 trigger2flow = triggerFlow2.Value;
                                if (trigger2.ForceFalloff)
                                {
                                    trigger2flow *= (1.0f - Vector2.Distance(blipPos, trigger2.WorldPosition) / trigger2.ColliderRadius);
                                }
                                blipVel += trigger2flow;
                            }
                        }
                        var flowBlip = new SonarBlip(blipPos, Rand.Range(0.5f, 1.0f), 1.0f)
                        {
                            Velocity = blipVel * Rand.Range(1.0f, 5.0f),
                            Size     = new Vector2(MathHelper.Lerp(0.4f, 5f, flowMagnitude / 500.0f), 0.2f),
                            Rotation = (float)Math.Atan2(-blipVel.Y, blipVel.X)
                        };
                        sonarBlips.Add(flowBlip);
                    }
                }
            }

            if (IsActive)
            {
                float pingRadius = DisplayRadius * pingState / zoom;
                UpdateDisruptions(transducerCenter, pingRadius / displayScale, prevPingRadius / displayScale);
                Ping(transducerCenter, transducerCenter,
                     pingRadius, prevPingRadius, displayScale, range / zoom, passive: false, pingStrength: 2.0f);
                prevPingRadius = pingRadius;
                return;
            }

            float passivePingRadius = (float)Math.Sin(Timing.TotalTime * 10);
            if (passivePingRadius > 0.0f)
            {
                disruptedDirections.Clear();
                foreach (AITarget t in AITarget.List)
                {
                    if (t.SoundRange <= 0.0f || !t.Enabled)
                    {
                        continue;
                    }

                    if (Vector2.DistanceSquared(t.WorldPosition, transducerCenter) < t.SoundRange * t.SoundRange)
                    {
                        Ping(t.WorldPosition, transducerCenter,
                             t.SoundRange * passivePingRadius * 0.2f, t.SoundRange * prevPassivePingRadius * 0.2f, displayScale, t.SoundRange,
                             passive: true, pingStrength: 0.5f);
                        sonarBlips.Add(new SonarBlip(t.WorldPosition, 1.0f, 1.0f));
                    }
                }
            }
            prevPassivePingRadius = passivePingRadius;
        }
Exemple #16
0
 void Start()
 {
     levelTriggerScript = levelTrigger.GetComponent <LevelTrigger>();
 }
Exemple #17
0
    // Update is called once per frame
    void Update()
    {
        try
        {
            levelTrigger = GameObject.FindGameObjectWithTag("levelTrigger").GetComponent <LevelTrigger>();
        }
        catch { }

        if (timerText != null)
        {
            // Timer Timings
            if (isTimerWorking && timerDelay == 0)
            {
                timerDelay = Time.time;
            }
            if (isTimerWorking && timerDelay != 0)
            {
                //startTime = startTime + timerDelay;


                float currentTime = startTime - Time.time + timerDelay;

                if (currentTime < 0)
                {
                    if (leavingAnimation != null)
                    {
                        if (SceneManager.GetActiveScene().name == "Level1-1" || SceneManager.GetActiveScene().name == "Level1-2L" || SceneManager.GetActiveScene().name == "Level1-2N")
                        {
                            // if (npc != null) npc.localEulerAngles = new Vector3(0f, 180f, 0f);
                            leavingAnimation.SetActive(true);
                        }
                    }
                }

                string minutes = ((int)currentTime / 60).ToString();
                string seconds = (currentTime % 60).ToString("f2");

                // Coloring of the text.

                if (currentTime > startTime / 2)
                {
                    try { levelTrigger.levelToLoadWhenTriggered = levelTransitionGoodTime; }

                    catch { }

                    timerText.color = Color.white;
                }
                else if (currentTime > startTime / 3)
                {
                    timerText.color = Color.yellow;
                }


                else if (currentTime < 0 && currentTime > (startTime / 2) * (-1f))
                {
                    try { levelTrigger.levelToLoadWhenTriggered = levelTransitionBadTime; }
                    catch { }
                    timerText.color = Color.red;
                }
                else if (currentTime < (startTime / 2) * (-1f))
                {
                    timerText.color = Color.gray;
                    try { levelTrigger.levelToLoadWhenTriggered = levelTransitionWorstTime; }
                    catch { }
                }



                timerText.text = minutes + " : " + seconds;
            }
            else
            {
                timerText.text = "";
            }
        }
    }
Exemple #18
0
 void Awake()
 {
     _levelTriggerRef = transform.parent.GetComponent <LevelTrigger>();
 }