void Update()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            if (character.IsDead())
            {
                return;
            }

            //Swim
            if (!is_swimming && PhysicsTool.IsAnyLayerIsInLayerMask(cground_layers, water_layer))
            {
                StartSwim();
            }
            else if (is_swimming && !PhysicsTool.IsAnyLayerIsInLayerMask(cground_layers, water_layer))
            {
                StopSwimming();
            }

            //Swim adjust offset
            if (swim_mesh_offset != null)
            {
                swim_mesh_offset.transform.localPosition = Vector3.Lerp(swim_mesh_offset.transform.localPosition, swim_mesh_tpos, 20f * Time.deltaTime);
            }
        }
Beispiel #2
0
 void Update()
 {
     if (TheGame.Get().IsPaused())
     {
         return;
     }
 }
Beispiel #3
0
        void Update()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            float game_speed = TheGame.Get().GetGameTimeSpeedPerSec();

            item_progress += game_speed * Time.deltaTime;
            if (item_progress > item_spawn_time)
            {
                item_progress = 0f;
                nb_item      += 1;
                nb_item       = Mathf.Min(nb_item, item_max);

                PlayerData.Get().SetCustomValue(GetAmountUID(), nb_item);
            }

            for (int i = 0; i < item_models.Length; i++)
            {
                bool visible = (i < nb_item);
                if (item_models[i].activeSelf != visible)
                {
                    item_models[i].SetActive(visible);
                }
            }
        }
        void Update()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            if (was_spawned && selectable.IsActive())
            {
                PlayerData      pdata        = PlayerData.Get();
                DroppedItemData dropped_item = pdata.GetDroppedItem(GetUID());
                if (dropped_item != null)
                {
                    if (data.HasDurability() && dropped_item.durability <= 0f)
                    {
                        DestroyItem(); //Destroy item from durability
                    }
                }
            }

            if (auto_collect_range > 0.1f)
            {
                PlayerCharacter player = PlayerCharacter.GetNearest(transform.position, auto_collect_range);
                if (player != null)
                {
                    player.Inventory.AutoTakeItem(this);
                }
            }
        }
Beispiel #5
0
    void Update()
    {
        if (TheGame.Get().IsPaused())
        {
            return;
        }

        //Remove null
        for (int i = spawn_list.Count - 1; i >= 0; i--)
        {
            if (spawn_list[i] == null || !spawn_list[i].activeSelf)
            {
                spawn_list.RemoveAt(i);
            }
        }

        if (!IsFull())
        {
            float game_speed  = GameData.Get().game_time_mult;
            float hour_to_sec = game_speed / 3600f;

            spawn_timer += hour_to_sec * Time.deltaTime;
            if (spawn_timer > spawn_interval)
            {
                spawn_timer = 0f;
                Spawn();
            }
        }
    }
        void Update()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            if (IsDead())
            {
                return;
            }

            //Attack when target is in range
            if (!character.IsDoingAction())
            {
                attack_timer += Time.deltaTime;
            }

            Destructible auto_move_attack = character.GetAutoAttackTarget();

            if (auto_move_attack != null && !character.IsDoingAction() && IsAttackTargetInRange(auto_move_attack))
            {
                character.FaceTorward(auto_move_attack.transform.position);
                character.PauseAutoMove(); //Reached target, dont keep moving

                if (attack_timer > GetAttackCooldown())
                {
                    DoAttack(auto_move_attack);
                }
            }
        }
Beispiel #7
0
    void Update()
    {
        if (TheGame.Get().IsPaused())
        {
            return;
        }

        float game_speed  = GameData.Get().game_time_mult;
        float hour_to_sec = game_speed / 3600f;

        item_progress += hour_to_sec * Time.deltaTime;
        if (item_progress > item_spawn_time)
        {
            item_progress = 0f;
            nb_item      += 1;
            nb_item       = Mathf.Min(nb_item, item_max);

            PlayerData.Get().SetUniqueID(GetAmountUID(), nb_item);
        }

        for (int i = 0; i < item_models.Length; i++)
        {
            bool visible = (i < nb_item);
            if (item_models[i].activeSelf != visible)
            {
                item_models[i].SetActive(visible);
            }
        }
    }
Beispiel #8
0
        void Update()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            if (HasItem())
            {
                float game_speed = TheGame.Get().GetGameTimeSpeedPerSec();
                timer += game_speed * Time.deltaTime;
                if (timer > duration)
                {
                    FinishItem();
                }

                if (progress != null)
                {
                    progress.manual_value = timer / duration;
                }

                if (active_fx != null && active_fx.activeSelf != HasItem())
                {
                    active_fx.SetActive(HasItem());
                }
            }
        }
Beispiel #9
0
        void Update()
        {
            pause_panel.SetVisible(TheGame.Get().IsPausedByPlayer());

            foreach (PlayerControls controls in PlayerControls.GetAll())
            {
                if (controls.IsPressPause() && !TheGame.Get().IsPausedByPlayer())
                {
                    TheGame.Get().Pause();
                }
                else if (controls.IsPressPause() && TheGame.Get().IsPausedByPlayer())
                {
                    TheGame.Get().Unpause();
                }
            }

            //Gamepad auto focus
            UISlotPanel focus_panel = UISlotPanel.GetFocusedPanel();

            if (focus_panel != pause_panel && TheGame.Get().IsPausedByPlayer() && PlayerControls.IsAnyGamePad())
            {
                pause_panel.Focus();
            }
            if (focus_panel == pause_panel && !TheGame.Get().IsPausedByPlayer())
            {
                UISlotPanel.UnfocusAll();
            }
        }
 public void StopSleep()
 {
     if (is_sleep)
     {
         is_sleep     = false;
         sleep_target = null;
         TheGame.Get().SetGameSpeedMultiplier(1f);
     }
 }
Beispiel #11
0
 private void Start()
 {
     if (mode == WorldGeneratorMode.Runtime && Application.isPlaying)
     {
         TheGame.Get().PauseScripts();
         BlackPanel.Get().Show(true);
         GeneratedOrLoadWorld();
         BlackPanel.Get().Hide();
         TheGame.Get().UnpauseScripts();
     }
 }
        //---- Special actions

        public void Sleep(ActionSleep sleep_target)
        {
            if (!is_sleep && !is_riding && !IsSwimming())
            {
                this.sleep_target = sleep_target;
                is_sleep          = true;
                auto_move         = false;
                auto_move_attack  = null;
                TheGame.Get().SetGameSpeedMultiplier(sleep_target.sleep_speed_mult);
            }
        }
        void Update()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            if (buildable.IsBuilding())
            {
                return;
            }

            float game_speed = TheGame.Get().GetGameTimeSpeedPerSec();

            if (!IsFullyGrown() && grow_time > 0.001f)
            {
                growth_progress += game_speed * boost_mult * Time.deltaTime;
                PlayerData.Get().SetCustomValue(GetProgressUID(), Mathf.RoundToInt(growth_progress));

                if (growth_progress > grow_time)
                {
                    GrowPlant();
                    return;
                }
            }

            if (!has_fruit && fruit != null)
            {
                fruit_progress += game_speed * boost_mult * Time.deltaTime;
                PlayerData.Get().SetCustomValue(GetProgressUID(), Mathf.RoundToInt(fruit_progress));

                if (fruit_progress > fruit_grow_time)
                {
                    GrowFruit();
                    return;
                }
            }

            //Boost stop
            if (boost_timer > 0f)
            {
                boost_timer -= game_speed * Time.deltaTime;
                if (boost_timer <= 0.01f)
                {
                    boost_mult = 1f;
                }
            }

            //Display
            if (fruit_model != null && has_fruit != fruit_model.gameObject.activeSelf)
            {
                fruit_model.gameObject.SetActive(has_fruit);
            }
        }
Beispiel #14
0
    void Update()
    {
        bool paused = TheGame.Get().IsPaused();

        animator.enabled = !paused;

        if (animator.enabled)
        {
            animator.SetBool(move_anim, character.IsMoving());
            animator.SetBool(sleep_anim, character.IsSleeping());
        }
    }
Beispiel #15
0
        void Update()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            state_timer += Time.deltaTime;

            if (state == BirdState.Sit)
            {
                if (state_timer > sit_duration)
                {
                    FlyAway();
                }
            }

            if (state == BirdState.Alerted)
            {
                if (state_timer > reaction_time)
                {
                    FlyAway();
                }
            }

            if (state == BirdState.Fly)
            {
                if (fly_model.gameObject.activeSelf && character.HasReachedMoveTarget())
                {
                    fly_model.gameObject.SetActive(false);
                }

                if (state_timer > fly_duration)
                {
                    StopFly();
                }
            }

            if (state == BirdState.FlyDown)
            {
                if (character.HasReachedMoveTarget())
                {
                    Land();
                }
            }

            update_timer += Time.deltaTime;
            if (update_timer > 0.5f)
            {
                update_timer = Random.Range(-0.02f, 0.02f);
                SlowUpdate(); //Optimization
            }
        }
        void Update()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            float game_speed = TheGame.Get().GetGameTimeSpeedPerSec();

            //Calculate heat
            float total_heat        = global_heat * global_heat_weight;
            float total_heat_weight = global_heat_weight;

            foreach (HeatSource source in HeatSource.GetAll())
            {
                float dist = (source.transform.position - transform.position).magnitude;
                if (source.enabled && dist < source.heat_range)
                {
                    total_heat        += source.heat * source.heat_weight;
                    total_heat_weight += source.heat_weight;
                }
            }

            //Character heat will move toward this value
            float average_heat = total_heat / total_heat_weight;
            float current_heat = character.Attributes.GetAttributeValue(AttributeType.Heat);
            float change_speed = heat_change_speed;
            float dir          = average_heat - current_heat;

            //Cold resist
            if (dir < 0f)
            {
                float resist = cold_resist + character.Attributes.GetBonusEffectTotal(BonusType.ColdResist);
                change_speed = change_speed / (1f + resist);
            }

            //Update heat
            if (Mathf.Abs(dir) > 0.1f)
            {
                current_heat += Mathf.Sign(dir) * change_speed * game_speed * Time.deltaTime;
                character.Attributes.SetAttribute(AttributeType.Heat, current_heat);
            }

            //Deal damage
            if (current_heat < damage_threshold + 0.01f)
            {
                float update_value = damage_hp_loss * game_speed * Time.deltaTime;
                character.Attributes.AddAttribute(AttributeType.Health, update_value);
            }

            //Debug.Log(average_heat + " " + current_heat + " " + change_speed);
        }
        void FixedUpdate()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            //Optimization, dont run if too far
            float dist         = (TheCamera.Get().GetTargetPos() - transform.position).magnitude;
            float active_range = Mathf.Max(detect_range * 2f, selectable.active_range * 0.8f);

            is_active = (state != AnimalState.Wander && state != AnimalState.Dead) || character.IsMoving() || dist < active_range;
        }
Beispiel #18
0
    public void OnClickPause()
    {
        if (TheGame.Get().IsPaused())
        {
            TheGame.Get().Unpause();
        }
        else
        {
            TheGame.Get().Pause();
        }

        TheAudio.Get().PlaySFX("UI", ui_sound);
    }
        void Update()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            if (character.IsDead())
            {
                return;
            }

            jump_timer -= Time.deltaTime;
        }
Beispiel #20
0
    void Start()
    {
        //Light
        GameData gdata    = GameData.Get();
        bool     is_night = TheGame.Get().IsNight();

        dir_light = FindObjectOfType <Light>();
        float target = is_night ? gdata.night_light_ambient_intensity : gdata.day_light_ambient_intensity;

        RenderSettings.ambientIntensity = target;
        if (dir_light != null && dir_light.type == LightType.Directional)
        {
            dir_light.intensity = is_night ? gdata.night_light_dir_intensity : gdata.day_light_dir_intensity;
        }
    }
Beispiel #21
0
        void FixedUpdate()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            if (IsDead())
            {
                return;
            }

            if (rider == null)
            {
                return;
            }
        }
Beispiel #22
0
    void Update()
    {
        bool paused = TheGame.Get().IsPaused();

        animator.enabled = !paused && select.IsActive();

        if (animator.enabled)
        {
            animator.SetBool("Move", animal.IsMoving() && animal.IsActive());
            animator.SetBool("Run", animal.IsRunning() && animal.IsActive());

            if (animator_outline != null)
            {
                animator_outline.Play(animator.GetCurrentAnimatorStateInfo(0).fullPathHash, 0, animator.GetCurrentAnimatorStateInfo(0).normalizedTime);
            }
        }
    }
        private void FixedUpdate()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            if (character.IsDead())
            {
                return;
            }

            Vector3 center  = character.GetColliderCenter();
            float   hradius = character.GetColliderHeightRadius();

            cground_layers = PhysicsTool.DetectGroundLayers(center, hradius);
        }
Beispiel #24
0
        void Update()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            if (IsDead())
            {
                return;
            }

            if (rider != null)
            {
                PlayerControls      controls  = PlayerControls.Get(rider.player_id);
                PlayerControlsMouse mcontrols = PlayerControlsMouse.Get();
                Vector3             tmove     = Vector3.zero;
                Vector3             cam_move  = TheCamera.Get().GetRotation() * controls.GetMove();
                if (mcontrols.IsJoystickActive())
                {
                    Vector2 joystick = mcontrols.GetJoystickDir();
                    cam_move = TheCamera.Get().GetRotation() * new Vector3(joystick.x, 0f, joystick.y);
                }
                tmove = cam_move * ride_speed;
                if (tmove.magnitude > 0.1f)
                {
                    character.DirectMoveToward(tmove);
                }

                //Character stuck
                if (tmove.magnitude < 0.1f && character.IsStuck())
                {
                    character.Stop();
                }
            }

            //Animations
            if (animator.enabled)
            {
                animator.SetBool("Move", IsMoving());
                animator.SetBool("Run", IsMoving());
            }
        }
Beispiel #25
0
        void Update()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            float game_speed = TheGame.Get().GetGameTimeSpeedPerSec();

            spawn_timer += game_speed * Time.deltaTime;

            PlayerData.Get().SetCustomValue(GetTimerUID(), Mathf.RoundToInt(spawn_timer));

            if (spawn_timer > spawn_interval)
            {
                spawn_timer = 0f;
                SpawnIfNotMax();
            }
        }
Beispiel #26
0
        void Update()
        {
            //Shake FX
            if (is_shaking)
            {
                shake_timer -= Time.deltaTime;

                if (shake_timer > 0f)
                {
                    shake_vector        = new Vector3(Mathf.Cos(shake_timer * Mathf.PI * 16f) * 0.02f, 0f, Mathf.Sin(shake_timer * Mathf.PI * 8f) * 0.01f);
                    transform.position += shake_vector * shake_intensity;
                }
                else if (shake_timer > -0.5f)
                {
                    transform.position = Vector3.Lerp(transform.position, shake_center, 4f * Time.deltaTime);
                }
                else
                {
                    is_shaking = false;
                }
            }

            //Spawn HP bar
            if (hp > 0 && hp < max_hp && hbar == null && hp_bar != null)
            {
                GameObject hp_obj = Instantiate(hp_bar, transform);
                hbar        = hp_obj.GetComponent <HPBar>();
                hbar.target = this;
            }

            //Regen HP
            if (!dead && hp_regen > 0.01f && hp < max_hp)
            {
                float game_speed = TheGame.Get().GetGameTimeSpeedPerSec();
                hp_regen_val += game_speed * Time.deltaTime;
                if (hp_regen_val >= 1f)
                {
                    hp_regen_val -= 1f;
                    hp           += 1;
                }
            }
        }
Beispiel #27
0
    void Update()
    {
        if (TheGame.Get().IsPaused())
        {
            return;
        }

        //Check if dead
        PlayerCharacter character = PlayerCharacter.Get();

        if (character.IsDead())
        {
            death_timer += Time.deltaTime;
            if (death_timer > 2f)
            {
                enabled = false; //Stop running this loop
                TheUI.Get().ShowGameOver();
            }
        }

        //Game time
        PlayerData pdata       = PlayerData.Get();
        GameData   gdata       = GameData.Get();
        float      game_speed  = GameData.Get().game_time_mult;
        float      hour_to_sec = game_speed / 3600f;

        pdata.day_time += hour_to_sec * Time.deltaTime;
        if (pdata.day_time >= 24f)
        {
            pdata.day_time = 0f;
            pdata.day++; //New day
        }

        //Set music
        AudioClip[] music_playlist = GameData.Get().music_playlist;
        if (music_playlist.Length > 0 && !TheAudio.Get().IsMusicPlaying("music"))
        {
            AudioClip clip = music_playlist[Random.Range(0, music_playlist.Length)];
            TheAudio.Get().PlayMusic("music", clip, 0.4f, false);
        }
    }
Beispiel #28
0
    void Update()
    {
        //Day night
        GameData gdata    = GameData.Get();
        bool     is_night = TheGame.Get().IsNight();
        float    target   = is_night ? gdata.night_light_ambient_intensity : gdata.day_light_ambient_intensity;

        RenderSettings.ambientIntensity = Mathf.MoveTowards(RenderSettings.ambientIntensity, target, 0.2f * Time.deltaTime);
        if (dir_light != null && dir_light.type == LightType.Directional)
        {
            float dtarget = is_night ? gdata.night_light_dir_intensity : gdata.day_light_dir_intensity;
            dir_light.intensity = Mathf.MoveTowards(dir_light.intensity, dtarget, 0.2f * Time.deltaTime);
        }

        //Slow update
        update_timer += Time.deltaTime;
        if (update_timer > 0.5f)
        {
            update_timer = 0f;
            SlowUpdate();
        }
    }
        void Update()
        {
            bool player_paused   = TheGame.Get().IsPausedByPlayer();
            bool gameplay_paused = TheGame.Get().IsPausedByGameplay();

            animator.enabled = !player_paused;

            if (animator.enabled)
            {
                animator.SetBool(move_anim, !gameplay_paused && character.IsMoving());
                animator.SetBool(craft_anim, !gameplay_paused && character.Crafting.IsCrafting());
                animator.SetBool(sleep_anim, character.IsSleeping());
                animator.SetBool(fish_anim, character.IsFishing());
                animator.SetBool(ride_anim, character.IsRiding());
                animator.SetBool(swim_anim, character.IsSwimming());

                float   mangle    = Vector3.SignedAngle(character.GetFacing(), character.GetMove(), Vector3.up);
                Vector3 move_side = new Vector3(Mathf.Sin(mangle * Mathf.Deg2Rad), 0f, Mathf.Cos(mangle * Mathf.Deg2Rad));
                animator.SetFloat(move_side_x, move_side.x);
                animator.SetFloat(move_side_z, move_side.z);
            }
        }
Beispiel #30
0
    void Update()
    {
        if (TheGame.Get().IsPaused())
        {
            return;
        }

        float game_speed  = GameData.Get().game_time_mult;
        float hour_to_sec = game_speed / 3600f;

        if (!IsFullyGrown() && grow_time > 0.001f)
        {
            growth_progress += hour_to_sec * Time.deltaTime;
            if (growth_progress > grow_time)
            {
                growth_progress = 0f;
                GrowPlant();
                return;
            }
        }

        if (!has_fruit && fruit != null)
        {
            fruit_progress += hour_to_sec * Time.deltaTime;

            if (fruit_progress > fruit_grow_time)
            {
                has_fruit      = true;
                fruit_progress = 0f;
                PlayerData.Get().SetUniqueID(GetFruitUID(), 1);
            }
        }

        //Display
        if (fruit_model != null && has_fruit != fruit_model.gameObject.activeSelf)
        {
            fruit_model.gameObject.SetActive(has_fruit);
        }
    }