protected override void Awake()
        {
            base.Awake();
            character_list.Add(this);
            rigid       = GetComponent <Rigidbody>();
            selectable  = GetComponent <Selectable>();
            destruct    = GetComponent <Destructible>();
            buildable   = GetComponent <Buildable>();
            unique_id   = GetComponent <UniqueID>();
            colliders   = GetComponentsInChildren <Collider>();
            avoid_side  = Random.value < 0.5f ? 1f : -1f;
            facing      = transform.forward;
            use_navmesh = move_enabled && use_navmesh;

            move_target       = transform.position;
            move_target_avoid = transform.position;

            destruct.onDamaged += OnDamaged;
            destruct.onDeath   += OnDeath;

            if (buildable != null)
            {
                buildable.onBuild += OnBuild;
            }

            foreach (Collider collide in colliders)
            {
                float size = collide.bounds.extents.magnitude;
                if (size > bounds_extent.magnitude)
                {
                    bounds_extent        = collide.bounds.extents;
                    bounds_center_offset = collide.bounds.center - transform.position;
                }
            }
        }
Esempio n. 2
0
 void Awake()
 {
     station_list.Add(this);
     select        = GetComponent <Selectable>();
     buildable     = GetComponent <Buildable>();
     select.onUse += OnUse;
 }
 public void CancelBuilding()
 {
     if (current_buildable != null)
     {
         Destroy(current_buildable.gameObject);
         current_buildable  = null;
         current_build_data = null;
         build_callback     = null;
         clicked_build      = false;
     }
 }
        public void CompleteBuilding(Vector3 pos)
        {
            CraftData item = current_crafting;

            if (item != null && current_buildable != null && (!build_pay_cost || CanCraft(item, true)))
            {
                current_buildable.SetBuildPositionTemporary(pos); //Set to position to test the condition, before applying it

                if (current_buildable.CheckIfCanBuild())
                {
                    current_buildable.SetBuildPosition(pos);

                    character.FaceTorward(pos);

                    if (build_pay_cost)
                    {
                        PayCraftingCost(item);
                    }

                    Buildable buildable = current_buildable;
                    buildable.FinishBuild();

                    character.Data.AddCraftCount(item.id);

                    UnityAction <Buildable> bcallback = build_callback;
                    current_buildable  = null;
                    current_build_data = null;
                    build_callback     = null;
                    clicked_build      = false;
                    character.StopAutoMove();

                    PlayerUI.Get(character.player_id)?.CancelSelection();
                    TheAudio.Get().PlaySFX("craft", buildable.build_audio);

                    if (onBuild != null)
                    {
                        onBuild.Invoke(buildable);
                    }

                    if (bcallback != null)
                    {
                        bcallback.Invoke(buildable);
                    }

                    character.TriggerAction(1f);
                }
            }
        }
        protected override void Awake()
        {
            base.Awake();
            plant_list.Add(this);
            selectable            = GetComponent <Selectable>();
            buildable             = GetComponent <Buildable>();
            destruct              = GetComponent <Destructible>();
            unique_id             = GetComponent <UniqueID>();
            selectable.onDestroy += OnDeath;
            buildable.onBuild    += OnBuild;

            if (data != null)
            {
                nb_stages = Mathf.Max(data.growth_stage_prefabs.Length, 1);
            }
        }
        public void CraftConstructionBuildMode(ConstructionData item, bool pay_craft_cost = true, UnityAction <Buildable> callback = null)
        {
            if (!pay_craft_cost || CanCraft(item))
            {
                CancelCrafting();

                Construction construction = Construction.CreateBuildMode(item, transform.position + transform.forward * 1f);
                current_buildable = construction.GetBuildable();
                current_buildable.StartBuild(character);
                current_build_data = item;
                clicked_build      = false;
                build_pay_cost     = pay_craft_cost;
                build_callback     = callback;
                build_timer        = 0f;
            }
        }
        public void CraftPlantBuildMode(PlantData plant, int stage, bool pay_craft_cost = true, UnityAction <Buildable> callback = null)
        {
            if (!pay_craft_cost || CanCraft(plant))
            {
                CancelCrafting();

                Plant aplant = Plant.CreateBuildMode(plant, transform.position, stage);
                current_buildable = aplant.GetBuildable();
                current_buildable.StartBuild(character);
                current_build_data = plant;
                clicked_build      = false;
                build_pay_cost     = pay_craft_cost;
                build_callback     = callback;
                build_timer        = 0f;
            }
        }
Esempio n. 8
0
        protected override void Awake()
        {
            base.Awake();
            construct_list.Add(this);
            selectable = GetComponent <Selectable>();
            buildable  = GetComponent <Buildable>();
            destruct   = GetComponent <Destructible>();
            unique_id  = GetComponent <UniqueID>();

            buildable.onBuild += OnBuild;

            if (selectable != null)
            {
                selectable.onDestroy += OnDeath;
            }
        }
Esempio n. 9
0
 void Awake()
 {
     firepit_list.Add(this);
     select       = GetComponent <Selectable>();
     construction = GetComponent <Construction>();
     buildable    = GetComponent <Buildable>();
     unique_id    = GetComponent <UniqueID>();
     heat_source  = GetComponent <HeatSource>();
     if (fire_fx)
     {
         fire_fx.SetActive(false);
     }
     if (fuel_model)
     {
         fuel_model.SetActive(false);
     }
 }
Esempio n. 10
0
        //Check if overlaping another object (cant build)
        public bool CheckIfOverlap()
        {
            List <Collider> overlap_colliders = new List <Collider>();
            LayerMask       olayer            = obstacle_layer & ~floor_layer; //Remove floor layer from obstacles

            //Check collision with bounding box
            foreach (Collider collide in colliders)
            {
                Collider[] over = Physics.OverlapBox(transform.position, collide.bounds.extents, Quaternion.identity, olayer);
                foreach (Collider overlap in over)
                {
                    if (!overlap.isTrigger)
                    {
                        overlap_colliders.Add(overlap);
                    }
                }
            }

            //Check collision with radius (includes triggers)
            if (build_obstacle_radius > 0.01f)
            {
                Collider[] over = Physics.OverlapSphere(transform.position, build_obstacle_radius, olayer);
                overlap_colliders.AddRange(over);
            }

            //Check collision list
            foreach (Collider overlap in overlap_colliders)
            {
                if (overlap != null)
                {
                    //Dont overlap with player and dont overlap with itself
                    PlayerCharacter player    = overlap.GetComponent <PlayerCharacter>();
                    Buildable       buildable = overlap.GetComponentInParent <Buildable>();
                    if (player == null && buildable != this)
                    {
                        return(true);
                    }
                }
            }

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

            if (IsDead())
            {
                return;
            }

            //Save position
            Data.position = GetPosition();

            //Controls
            PlayerControls controls = PlayerControls.Get(player_id);

            //Stop sleep
            if (is_action || IsMoving() || sleep_target == null)
            {
                StopSleep();
            }

            //Activate Selectable when near
            Vector3 move_dir = auto_move_target - transform.position;

            if (auto_move && !is_action && auto_move_select != null && move_dir.magnitude < auto_move_select.use_range)
            {
                auto_move = false;
                auto_move_select.Use(this, auto_move_target);
                auto_move_select = null;
            }

            //Finish construction when near clicked spot
            Buildable current_buildable = character_craft.GetCurrentBuildable();

            if (auto_move && !is_action && character_craft.ClickedBuild() && current_buildable != null && move_dir.magnitude < current_buildable.build_distance)
            {
                auto_move = false;
                character_craft.StartCraftBuilding(auto_move_target);
            }

            //Stop move & drop when near clicked spot
            if (auto_move && !is_action && move_dir.magnitude < moving_threshold * 2f)
            {
                auto_move = false;
                character_inventory.DropItem(auto_move_drop_inventory, auto_move_drop);
            }

            //Stop attacking if target cant be attacked anymore (tool broke, or target died...)
            if (!character_combat.CanAttack(auto_move_attack))
            {
                auto_move_attack = null;
            }

            //Ride animal
            if (is_riding)
            {
                if (riding_animal == null || riding_animal.IsDead())
                {
                    StopRide();
                    return;
                }

                transform.position = riding_animal.GetRideRoot();
                transform.rotation = Quaternion.LookRotation(riding_animal.transform.forward, Vector3.up);
            }

            //Controls
            if (IsControlsEnabled() && !is_action)
            {
                //Check if panel is focused
                KeyControlsUI ui_controls = KeyControlsUI.Get(player_id);
                bool          panel_focus = controls.gamepad_controls && ui_controls != null && ui_controls.IsPanelFocus();
                if (!panel_focus)
                {
                    //Press Action button
                    if (controls.IsPressAction())
                    {
                        if (character_craft.CanBuild())
                        {
                            character_craft.StartCraftBuilding();
                        }
                        else if (!panel_focus)
                        {
                            InteractWithNearest();
                        }
                    }

                    //Press attack
                    if (Combat.can_attack && controls.IsPressAttack())
                    {
                        AttackNearest();
                    }

                    //Press jump
                    if (character_jump != null && controls.IsPressJump())
                    {
                        character_jump.Jump();
                    }
                }

                if (controls.IsPressUISelect())
                {
                    if (character_craft.CanBuild())
                    {
                        character_craft.StartCraftBuilding();
                    }
                }
            }

            //Stop riding
            if (is_riding && (controls.IsPressJump() || controls.IsPressAction() || controls.IsPressUICancel()))
            {
                StopRide();
            }
        }
Esempio n. 12
0
 void Start()
 {
     active_model.SetActive(true);
     triggered_model.SetActive(false);
     buildable = GetComponent <Buildable>();
 }
 private void OnBuild(Buildable construction)
 {
     animator.SetTrigger(build_anim);
 }