コード例 #1
0
    public override void Tick(float deltaTime)
    {
        for (int i = 0; i < filters.Length; i++)
        {
            // cache variables
            Filter filter = filters[i];

            LightComponent lightComp = filter.lightComponent;
            InputComponent inputComp = filter.inputComponent;


            // ----- logic -----

            if (lightComp.currentCharges != 0)
            {
                if (inputComp.rightShoulderDown || Input.GetKeyDown(KeyCode.R))
                {
                    if (lightComp.currentFuel > 0)
                    {
                        SetLightActive(lightComp, !lightComp.IsLightEnabled(), true);
                    }
                }

                if (lightComp.currentFuel > 0 && lightComp.IsLightEnabled())
                {
                    DecayLight(lightComp, deltaTime);
                }
            }
            else if (inputComp.rightShoulderDown || Input.GetKeyDown(KeyCode.R))
            {
                FailAttemptSetLightActive(lightComp, !lightComp.IsLightEnabled(), true);
            }

            if (inputComp.leftBumberDown || Input.GetKeyDown(KeyCode.T))
            {
                DevRechargeTorches();
            }

            foreach (Light light in player.lightComponent.nearbyLights)
            {
                //Debug.Log(light.transform.parent.gameObject);
                if (!light.transform.parent.gameObject.activeSelf && player.lightComponent.nearbyLights.Contains(light))
                {
                    player.lightComponent.nearbyLights.Remove(light);
                    break;
                }
            }
        }
    }
コード例 #2
0
    public void ToggleLight()
    {
        if (plc.currentFuel > 0)
        {
            plc.SetLightEnabled(!plc.IsLightEnabled());
            ip.PulseVibrate(.2f);
            plc.PlayFizzle();
        }
        else
        {
            plc.PlayFizzle();
            ip.PulseVibrate(.1f);
        }

        mc.SetMovementAllowed(true);
    }
コード例 #3
0
ファイル: CombatSystem.cs プロジェクト: Syfrex/Owlchemist
    // for gizmos
    //private Projectile[] debugProjectiles;

    public override void Tick(float deltaTime)
    {
        for (int i = 0; i < filters.Length; i++)
        {
            // cache variables
            Filter filter = filters[i];

            CombatComponent combComp  = filter.combatComponent;
            InputComponent  inputComp = filter.inputComponent;


            // ----- logic -----

            if (inputComp.xButtonDown || Input.GetKeyDown(KeyCode.X))
            {
                PerformTorchSwing(combComp);
            }

            /*if (combComp.projectiles != null)
             * {
             *  MoveProjectiles(combComp.projectiles, deltaTime);
             *  HandleProjectileCollision(filter);
             * }
             *
             * if (combComp.isEngagedInCombat)
             * {
             *  if (inputComp.GetMouseButtonDown(0))
             *  {
             *      RaycastHit hit;
             *      inputComp.GetMouseWorldLocation(out hit);
             *      HealthComponent hc = hit.transform.GetComponentInParent<HealthComponent>();
             *
             *      if (hc)
             *      {
             *          LaunchProjectile(hc, combComp);
             *      }
             *  }
             * }
             *
             * debugProjectiles = combComp.projectiles;*/
        }

        LightComponent  lc = player.lightComponent;
        HealthComponent hc = player.healthComponent;

/*
 *      if (Input.GetKeyDown(KeyCode.H))
 *      {
 *          hc.RestoreGranularDamageOverTime(100f, 5f, true);
 *      }
 *      else if (Input.GetKeyDown(KeyCode.L))
 *      {
 *          hc.TakeGranularDamageOverTime(50f, 1f, true);
 *      }*/

        if (!hc.isHealing)
        {
            if (hc.isTakingDamage)
            {
                if (hc.healthAlterDuration > hc.currentAlterTime)
                {
                    float healthPercentage = hc.currentGranularHealth / hc.maxGranularHealth;

                    player.uiComponent.healthIndicator.SetImageFillAmount(hc.currentHealth, healthPercentage);
                    player.healthComponent.TakeGranularDamage(hc.alterTickAmount * deltaTime);
                    hc.currentAlterTime += Time.deltaTime;
                    return;
                }
                else
                {
                    hc.isTakingDamage = false;
                }
            }
            if (lc.nearbyLights.Count == 0 && !lc.IsLightEnabled())
            {
                if (hc.currentGranularHealth > 0)
                {
                    float healthPercentage = hc.currentGranularHealth / hc.maxGranularHealth;

                    player.uiComponent.healthIndicator.SetImageFillAmount(hc.currentHealth, healthPercentage);
                    player.healthComponent.TakeGranularDamage(hc.darknessGranularHealthDrain * deltaTime);
                }
            }
            else
            {
                if (hc.currentGranularHealth <= hc.maxGranularHealth && !player.combatComponent.isRunning)
                {
                    float healthPercentage = hc.currentGranularHealth / hc.maxGranularHealth;

                    player.uiComponent.healthIndicator.SetImageFillAmount(hc.currentHealth, healthPercentage);
                    player.healthComponent.RestoreGranularDamage(hc.granularHealthRestorationAmount * deltaTime);
                }
            }
        }
        else
        {
            if (hc.healthAlterDuration > hc.currentAlterTime && hc.currentGranularHealth <= hc.maxGranularHealth)
            {
                float healthPercentage = hc.currentGranularHealth / hc.maxGranularHealth;
                player.uiComponent.healthIndicator.SetImageFillAmount(hc.currentHealth, healthPercentage);
                player.healthComponent.RestoreGranularDamage(hc.alterTickAmount * deltaTime);
                hc.currentAlterTime += Time.deltaTime;
            }
            else
            {
                hc.isHealing = false;
            }
        }
    }
コード例 #4
0
    public override void Tick(float deltaTime)
    {
        for (int i = 0; i < filters.Length; i++)
        {
            // cache variables
            Filter filter = filters[i];

            InventoryComponent  invComp        = filter.inventoryComponent;
            InputComponent      inputComp      = filter.inputComponent;
            InteractorComponent interactorComp = filter.interactorComponent;
            MovementComponent   movComp        = filter.movementComponent;

            // ----- logic -----
            CheckDistanceToInteractable(filter);
            FindVisibleTargets();

            // no longer used---------------------------
            InteractMode previous = interactorComp.interactMode;
            if (inputComp.GetKeyDown(KeyCode.Alpha1))
            {
                // move set none if previous was new to SetInteractMode
                interactorComp.SetInteractMode(InteractMode.PlacingPlanks);
                if (previous == InteractMode.PlacingPlanks)
                {
                    interactorComp.SetInteractMode(InteractMode.None);
                }
            }
            else if (inputComp.GetKeyDown(KeyCode.Alpha2))
            {
                interactorComp.SetInteractMode(InteractMode.Combat);
                if (previous == InteractMode.Combat)
                {
                    interactorComp.SetInteractMode(InteractMode.None);
                }
            }
            //--------------------------------------------------

            if (inputComp.GetKeyDown(KeyCode.E) || inputComp.GetButtonDown("Fire1"))
            {
                //AttemptWorldInteract(interactorComp, player.inventoryComponent, inputComp.worldInteractMask);
                //interactorComp.SetInteractMode(InteractMode.Object);
            }
            else if (inputComp.GetKeyDown(KeyCode.Escape))
            {
                interactorComp.interactMode = InteractMode.None;
                CartComponent tc = (CartComponent)interactorComp.currentInteractable;
                if (tc)
                {
                    tc.isTraveling = true;
                }
            }

            if (Vector3.Distance(filter.gameObject.transform.position, transportableComponent.transform.position) < 6f ||
                Vector3.Distance(filter.gameObject.transform.position, travelComponent.transform.position) < 6f && lightComponent.IsLightEnabled())
            {
                goapSystem?.SetLightState(true);
            }
            else
            {
                goapSystem?.SetLightState(false);
            }

            if (Vector3.Distance(filter.gameObject.transform.position, transportableComponent.transform.position) < 3f)
            {
                if (inputComp.GetKeyDown(KeyCode.B) || inputComp.GetButtonDown("Fire3"))
                {
                    //bookGO.SetActive(!bookGO.activeSelf);
                    movComp.alive = false;
                }
                else
                {
                    movComp.alive = true;
                }

                if (inputComp.GetKeyDown(KeyCode.M) || inputComp.GetButtonDown("Fire2"))
                {
                    //mapGO.SetActive(!mapGO.activeSelf);
                }

                if (inputComp.GetKeyDown(KeyCode.E) || inputComp.GetButtonDown("Fire1"))
                {
                    //if (invComp.treeResources > 0)
                    //{
                    //    //craftingSystem?.CraftPotion1();
                    //    //craftGO.SetActive(!craftGO.activeSelf);
                    //}
                }
            }
            else
            {
                /*toggleMapGO.SetActive(false);
                 * toggleBookGO.SetActive(false);
                 * craftGO.SetActive(false);*/
            }

            isCombat      = interactorComp.interactMode == InteractMode.Combat;
            actorLocation = interactorComp.gameObject.transform.position;
            if (interactorComp.interactMode == InteractMode.PlacingPlanks)
            {
                isPlacingPlanks = true;
                if (isPlacingPlanks)
                {
                    // Don't LogWarning this unity I'm sure you have your reasons but I don't like them.
                }
                // TODO remaing at last possible location if impossible position
                plankPlaceLocation   = inputComp.GetMouseHoverTransformPosition(inputComp.objectPlaceMask);
                plankPlaceLocation.y = 0f;

                //if (inputComp.GetMouseButtonDown(0))
                //{
                //    PlacePlank(invComp);
                //}
            }
            else
            {
                isPlacingPlanks = false;
                if (inputComp.GetMouseButtonDown(0))
                {
                    inputComp.GetMouseWorldLocation(out RaycastHit hit);
                }
            }
        }
        if (Vector3.Distance(lightComponent.transform.position, transportableComponent.transform.position) < 7 && !lightComponent.IsLightEnabled()) //Magic number. Remove this
        {
            //lightComponent.currentFuel = lightComponent.maxFuel;
        }
    }