Beispiel #1
0
    private void PushPlayer(Rigidbody rb, Vector3 delta, float dt)
    {
        CharacterController player = UFLevel.GetPlayer <CharacterController>();
        Collider            col    = rb.GetComponent <Collider>();

        if (!InMoveRadius(col, delta, player))
        {
            return;
        }

        float dist = delta.magnitude;

        Vector3   center    = player.transform.position + player.center;
        float     capDist   = .5f * player.height - 2f * player.radius;
        Vector3   capOffset = capDist * Vector3.up;
        Vector3   p1        = center + capOffset;
        Vector3   p2        = center - capOffset;
        LayerMask mask      = 1 << rb.gameObject.layer;

        RaycastHit[] hits = Physics.CapsuleCastAll(p1, p2, player.radius, -delta, dist, mask);
        foreach (RaycastHit hit in hits)
        {
            if (hit.collider == col)
            {
                Vector3 push = hit.distance * delta.normalized;
                player.GetComponent <UFPlayerMovement>().GetPushed(push, dist / dt);
                return;
            }
        }
    }
Beispiel #2
0
    private void Update()
    {
        if (UFLevel.player == null)
        {
            return;
        }

        playerMissingTime += Time.deltaTime;
        playerMissingFrames++;
        if (playerMissingTime > 1f && playerMissingFrames > 10)
        {
            UFLevel.GetPlayer <UFPlayerLife>().TakeDamage(500f * Time.deltaTime,
                                                          UFPlayerLife.DamageType.exitLevel, true);
        }
    }
Beispiel #3
0
    /// <summary>
    /// Checks if conditions for this detector event are met and returns true if so
    /// </summary>
    private bool Detect()
    {
        //preperatory variables
        float countDownValue = UFLevel.GetPlayer <UFPlayerMovement>().GetCountDownValue();

        switch (type)
        {
        case UFLevelStructure.Event.EventType.When_Countdown_Over:
            return(countDownValue - Time.deltaTime <= 0f && countDownValue > 0f);

        case UFLevelStructure.Event.EventType.When_Countdown_Reaches:
            return(countDownValue - Time.deltaTime <= int1 && countDownValue > int1);

        default:
            Debug.LogError("Event type " + type + " not implemented");
            return(false);
        }
    }
Beispiel #4
0
    private void WriteDebugInfo(bool active)
    {
        debugPanel.SetActive(active);
        if (!active)
        {
            return;
        }

        PlayerMovement pm = UFLevel.GetPlayer <PlayerMovement>();

        if (pm != null)
        {
            debugText.text = pm.GetDebugText();
        }
        else
        {
            debugText.text = "No player info";
        }
    }
Beispiel #5
0
    public void DoContinuousEffect()
    {
        switch (type)
        {
        case UFLevelStructure.Event.EventType.Continuous_Damage:
            //TODO use damage type (int2)
            float dps = int1;
            if (int1 <= 0)
            {
                dps = float.PositiveInfinity;
            }
            UFLevel.GetPlayer <UFPlayerLife>().TakeDamage(Time.deltaTime * dps, int2, true);
            break;

        default:
            Debug.LogError("Event type " + type + " not implemented");
            break;
        }
    }
Beispiel #6
0
    private void SaveProperties()
    {
        if (LoweringRecord())
        {
            Global.match.TrackDifficulty(difficultyDropdown.value);
        }

        Global.save.playerName     = FilterName(playerNameInput.text);
        Global.save.difficulty     = difficultyDropdown.value;
        Global.save.allowShortJump = shortJumpToggle.isOn;
        Global.save.overrideStats  = overrideStatsToggle.isOn;
        Global.save.stableJump     = stabilizeDoubleJumpToggle.isOn;
        ApplyVolume();

        if (inLevel)
        {
            Global.save.SetPlayerStats(UFLevel.GetPlayer <PlayerMovement>());
        }
    }
Beispiel #7
0
    private void Update()
    {
        if (inside)
        {
            insideTime += Time.deltaTime;
            if (insideTime >= insideDelay)
            {
                if (requireUseKey)
                {
                    bool key = buttonTime <= 0f && Input.GetKeyDown(useKey);
                    key |= buttonTime > 0f && Input.GetKey(useKey);
                    if (key)
                    {
                        buttonTime += Time.deltaTime;
                        if (buttonTime >= buttonDelay)
                        {
                            Trigger();
                        }
                    }
                    else
                    {
                        buttonTime = 0f;
                    }

                    if (resetsRemaining != 0)
                    {
                        UFLevel.GetPlayer <UFPlayerMovement>().InButtonRange(useKey);
                    }
                }
                else
                {
                    Trigger();
                }
            }
        }
        else
        {
            insideTime = 0f;
        }
    }
Beispiel #8
0
    private void Update()
    {
        if (UFLevel.player == null)
        {
            return;
        }

        buttonAlert.SetBool("Visible", inButtonRange);
        inButtonRange = false;

        UFPlayerLife life = UFLevel.GetPlayer <UFPlayerLife>();

        float healthFrac = Mathf.Clamp01(life.GetHealth() / UFPlayerLife.MAX_HP);
        float armorFrac  = Mathf.Clamp01(life.GetArmor() / UFPlayerLife.MAX_HP);

        healthGauge.color = Color.Lerp(Color.red, Color.green, healthFrac);
        armorGauge.color  = Color.Lerp(Color.black, Color.yellow, armorFrac);
        healthGauge.transform.localScale = healthFrac * Vector3.one;
        armorGauge.fillAmount            = armorFrac;

        SetTimer(UFLevel.singleton.GetCountDownTime());

        if (weaponTagPanelTimer.TickTrigger())
        {
            weaponTagPanel.gameObject.SetActive(false);
        }

        matchTimerText.gameObject.SetActive(!PhotonNetwork.offlineMode);
        float matchTime = Global.match.timeLeft;

        if (matchTime < 10f)
        {
            matchTimerText.text = UFUtils.GetTimeString(matchTime, 1);
        }
        else
        {
            matchTimerText.text = UFUtils.GetTimeString(Mathf.FloorToInt(matchTime));
        }
    }
Beispiel #9
0
 public void Respawn()
 {
     UFLevel.GetPlayer <PlayerLife>().RespawnDie();
     CloseMenu();
 }
Beispiel #10
0
    /// <summary>
    /// Perform effects of this event.
    /// Returns the type of IDRef that is used up when performing the event,
    /// these references do not get activated in the usual sense by this
    /// event type.
    /// </summary>
    private IDRef.Type DoEffect(bool positive)
    {
        //preperatory variables
        Transform        playerTr = UFLevel.GetPlayer <Transform>();
        UFPlayerLife     playerLi = UFLevel.GetPlayer <UFPlayerLife>();
        UFPlayerMovement playerMo = UFLevel.GetPlayer <UFPlayerMovement>();
        AudioSource      sound    = this.GetComponent <AudioSource>();

        //find effect type and do its effects. Return IDRefts that were used up.
        switch (type)
        {
        case UFLevelStructure.Event.EventType.Teleport:
            foreach (int link in links)
            {
                Transform t = UFLevel.GetByID(link).objectRef.transform;
                t.position = transform.position;
                t.rotation = transform.rotation;
            }
            return(IDRef.Type.None);

        case UFLevelStructure.Event.EventType.Teleport_Player:
            playerTr.position = transform.position;
            playerTr.GetComponent <CharacterController>().Move(Vector3.zero);
            playerMo.SetRotation(transform.rotation);
            return(IDRef.Type.None);

        case UFLevelStructure.Event.EventType.Music_Start:
            if (sound.clip == null)
            {
                Debug.LogWarning("Music event has no audio clip assigned: " + name);
            }
            sound.Play();
            return(IDRef.Type.None);

        case UFLevelStructure.Event.EventType.Play_Sound:
            sound.rolloffMode = AudioRolloffMode.Linear;
            if (float1 >= 0f)
            {
                sound.minDistance  = float1;
                sound.maxDistance  = float1 * 2f;
                sound.spatialBlend = 1f;
            }
            else
            {
                sound.spatialBlend = 0f;
            }
            if (sound.clip == null)
            {
                Debug.LogWarning("Play sound event has no audio clip assigned: " + name);
            }
            sound.loop = bool1;
            sound.Play();
            if (float2 > 0f && !bool1)
            {
                sound.SetScheduledEndTime(float2);
            }
            return(IDRef.Type.None);

        case UFLevelStructure.Event.EventType.Music_Stop:
            float fadeTime = float1;
            foreach (UFEvent e in GetEventsOfType(UFLevelStructure.Event.EventType.Music_Start))
            {
                StartCoroutine(e.FadeAudioSource(fadeTime, 0f));
            }
            return(IDRef.Type.None);

        case UFLevelStructure.Event.EventType.Particle_State:
            foreach (UFParticleEmitter pem in GetLinksOfType <UFParticleEmitter>(IDRef.Type.ParticleEmitter))
            {
                pem.Activate(positive);
            }
            return(IDRef.Type.ParticleEmitter);

        case UFLevelStructure.Event.EventType.Mover_Pause:
            foreach (UFMover mov in GetLinksOfType <UFMover>(IDRef.Type.Keyframe))
            {
                mov.Activate(!positive);
            }
            return(IDRef.Type.Keyframe);

        case UFLevelStructure.Event.EventType.Reverse_Mover:
            bool setForwardIfMoving = int1 != 0;
            foreach (UFMover mov in GetLinksOfType <UFMover>(IDRef.Type.Keyframe))
            {
                mov.Reverse(setForwardIfMoving);
            }
            return(IDRef.Type.Keyframe);

        case UFLevelStructure.Event.EventType.Modify_Rotating_Mover:
            bool  increase = string1.Equals("Increase");
            float factor   = increase ? 1f + (float1 / 100f) : 1f - (float1 / 100f);
            foreach (UFMover mov in GetLinksOfType <UFMover>(IDRef.Type.Keyframe))
            {
                mov.ChangeRotationSpeed(factor);
            }
            return(IDRef.Type.Keyframe);

        case UFLevelStructure.Event.EventType.Explode:
            float radius = float1;
            float damage = float2;
            bool  geo    = bool1;
            float dist   = (playerTr.position - transform.position).magnitude;
            if (dist < radius)
            {
                playerLi.TakeDamage(damage, UFPlayerLife.DamageType.Explosive, false);
            }
            if (geo)
            {
                Debug.LogWarning("Explosion " + name + " requested geo mod; this will not work as of now!");
            }
            GameObject explosionPrefab = obj as GameObject;
            if (explosionPrefab != null)
            {
                Vector3    explPos   = transform.position;
                Quaternion explRot   = transform.rotation;
                GameObject explosion = Instantiate(explosionPrefab, explPos, explRot, transform);
                explosion.transform.localScale = radius * 2f * Vector3.one;
            }
            else
            {
                Debug.LogWarning("Explosion prefab for event " + name + " was not provided!");
            }
            return(IDRef.Type.None);

        case UFLevelStructure.Event.EventType.Skybox_State:
            UFLevel.playerInfo.SetSkyboxRotation(string1, float1);
            return(IDRef.Type.None);

        case UFLevelStructure.Event.EventType.Bolt_State:
            foreach (UFBoltEmitter bem in GetLinksOfType <UFBoltEmitter>(IDRef.Type.BoltEmitter))
            {
                bem.Activate(positive);
            }
            return(IDRef.Type.BoltEmitter);

        case UFLevelStructure.Event.EventType.Push_Region_State:
            foreach (UFForceRegion pr in GetLinksOfType <UFForceRegion>(IDRef.Type.PushRegion))
            {
                pr.Activate(positive);
            }
            return(IDRef.Type.PushRegion);

        case UFLevelStructure.Event.EventType.Countdown_Begin:
            UFLevel.singleton.SetCountDown(int1);
            return(IDRef.Type.None);

        case UFLevelStructure.Event.EventType.Countdown_End:
            UFLevel.singleton.SetCountDown(0f);
            return(IDRef.Type.None);

        case UFLevelStructure.Event.EventType.Remove_Object:
            foreach (int link in links)
            {
                GameObject g = UFLevel.GetByID(link).objectRef;
                if (g == null)
                {
                    Debug.LogWarning("Trying to remove ID ref that does not exist: " + link);
                }
                else
                {
                    g.SetActive(false);
                }
            }
            return(IDRef.Type.All);

        case UFLevelStructure.Event.EventType.Heal:
            if (bool1)
            {
                UFLevel.GetPlayer <UFPlayerLife>().GainHealth(int1);
                return(IDRef.Type.None);
            }
            else
            {
                Debug.LogError("Entity heal not implemented");
                return(IDRef.Type.Entity);
            }

        case UFLevelStructure.Event.EventType.Set_Gravity:
            Physics.gravity = float1 * Vector3.down;
            return(IDRef.Type.None);

        default:
            Debug.LogError("Event type " + type + " not implemented");
            return(IDRef.Type.None);
        }
    }
Beispiel #11
0
 private void EnterLiquid()
 {
     this.player = UFLevel.GetPlayer <UFPlayerMovement>();
 }
Beispiel #12
0
    private bool PickUp()
    {
        UFPlayerLife life = UFLevel.GetPlayer <UFPlayerLife>();

        if (life.isDead)
        {
            return(false);
        }
        UFPlayerMoveSounds sound = life.GetComponentInChildren <UFPlayerMoveSounds>();

        switch (type)
        {
        case ItemType.Health:
            if (life.CanPickUpHealth())
            {
                life.GainHealth(count);
                sound.PickUpPowerup();
                return(true);
            }
            return(false);

        case ItemType.Armor:
            if (life.CanPickUpArmor())
            {
                life.GainArmor(count);
                sound.PickUpPowerup();
                return(true);
            }
            return(false);

        case ItemType.SuperHealth:
            sound.PickUpPowerup();
            life.SuperHealth();
            return(true);

        case ItemType.SuperArmor:
            sound.PickUpPowerup();
            life.SuperArmor();
            return(true);

        case ItemType.Invulnerability:
            sound.PickUpInvuln();
            life.Invulnerability();
            return(true);

        case ItemType.Explosive:
        case ItemType.Gun:
        case ItemType.SpecialWeapon:
            bool weapon = UFLevel.GetPlayer <UFPlayerWeapons>().PickupWeapon(this);
            if (weapon)
            {
                sound.PickUpWeapon();
            }
            return(weapon);

        case ItemType.ExplosiveAmmo:
        case ItemType.GunAmmo:
            bool ammo = UFLevel.GetPlayer <UFPlayerWeapons>().PickupAmmo(this);
            if (ammo)
            {
                sound.PickUpWeapon();
            }
            return(ammo);

        case ItemType.DamageAmp:
            UFLevel.GetPlayer <UFPlayerWeapons>().DamageAmp();
            sound.PickUpDamageAmp();
            return(true);

        default:
            Debug.LogWarning("Tried to collect unkown item type: " + type + " of item " + this.name);
            return(false);
        }
    }