public override void Down(Ray interactRay) { RaycastHit hitt; if (Physics.Raycast(interactRay, out hitt, PlayerInteraction.interactRange, LayerMask.GetMask("Harvestable"))) { Harvestable obj = hitt.collider.GetComponent <Harvestable>(); if (obj != null) { //maybe 2 different types? // one that pops off // one that you can just grab Sample newSample = SampleDatabase.Instance.GetSampleByID(obj.sampleId); if (obj.destroy) { Object.Destroy(obj.gameObject); SampleBehaviour.SpawnInWorld(newSample, hitt.point); //GameObject newObj = Object.Instantiate(newSample.worldPrefab, obj.transform.position, Quaternion.identity); //newObj.transform.localScale = obj.transform.localScale; } else { SampleBehaviour.SpawnInWorld(newSample, hitt.point); } } } }
public void Update(GameTime gameTime) { _camera.Update(gameTime); SM.Update(gameTime); _editor.Update(); EC.Update(); _man.Update(gameTime); if (InputHelper.IsNewKeyPress(Keys.H)) { // harvest foreach (KeyValuePair <int, BaseEntity> keypair in EC.All) { Harvestable beh = keypair.Value.GetProperty <Harvestable>(); if (beh != null) { beh.Harvest(keypair.Value); } if (keypair.Value.Schematic == EntitySchematics.Tree) { break; } } } }
private void Update() { Ray ray = cam.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0)); RaycastHit hit; if (Physics.Raycast(ray, out hit, 2)) { Harvestable harvestable = hit.collider.GetComponent <Harvestable>(); DirtyWater dirtyWater = hit.collider.GetComponent <DirtyWater>(); if (harvestable != null) { harvestPrompt(hit.transform.gameObject, hit.transform.name, harvestable.objectID, harvestable.objectAmt); } else if (dirtyWater != null) { //print("Is looking at dirty water?"); //print(toolBelt.currentItemID); dirtyWaterPrompt(hit.transform.name, dirtyWater.waterID); } //print("I'm looking at " + hit.transform.name); //if (hit.transform.name == "Mushroom001") //{ // Destroy(hit.transform.gameObject); // inventory.AddItem(itemDatabase.GetItemById(5), 2); // } } else { pickUpPrompt.SetActive(false); } }
public void SetHarvestable(Harvestable harvestableObj) { Harvestable = GeneralMethods.CopyObject(harvestableObj); Harvestable.MaterialsRemaining = Harvestable.RegensResources ? Harvestable.MaxAtOnce : Random.Range(Harvestable.MinObtainable, Harvestable.MaxObtainable + 1); }
public bool CanBeHarvested() { Harvestable component = GetComponent <Harvestable>(); if ((UnityEngine.Object)component != (UnityEngine.Object)null) { return(component.CanBeHarvested); } return(true); }
public static void Init(ContentManager content, Effect effect) { // -- TREE -- \\ Tree = new EntitySchematic(); Tree.RenderBasic = new RenderBasic(content.Load <Model>("Models/Entity/tree"), effect); Tree.OccupiedSpace = new List <Vector3>(); Tree.OccupiedSpace.Add(Vector3.Zero); Tree.OccupiedSpace.Add(new Vector3(0, 1, 0)); Tree.OccupiedSpace.Add(new Vector3(0, 2, 0)); Tree.OccupiedSpace.Add(new Vector3(0, 3, 0)); Tree.RenderOffset = new Vector3(0, 0.85f, 0); Tree.BaseScale = new Vector3(0.8f, 0.8f, 0.75f); Tree.Name = "Tree"; Tree.Description = "It's a tree, not much else can be said."; // Harvest behaviour Harvestable onHarvest = new Harvestable(); onHarvest.AddAction((e => e.RemoveSelf())); onHarvest.AddAction((e => e.GW.AddEntityByChance(new BaseEntity(e.GW, EntitySchematics.Log, e.Position), 1))); onHarvest.AddAction((e => e.GW.AddEntityByChance(new BaseEntity(e.GW, EntitySchematics.Log, e.Position + WorldDirection.North), 2))); Tree.Behaviours = new Dictionary <Type, BaseProperty>(); Tree.Behaviours.Add(typeof(Harvestable), onHarvest); // -- LOG -- \\ Log = new EntitySchematic(); Log.RenderBasic = new RenderBasic(content.Load <Model>("Models/Entity/log3"), effect); Log.OccupiedSpace = new List <Vector3>(); Log.BaseScale = new Vector3(0.1f, 0.1f, 0.25f); Log.RenderOffset = new Vector3(0f, -0.15f, 0f); Log.Name = "Log"; Log.Description = "It's big, it's heavy, it's wood."; Log.Behaviours = new Dictionary <Type, BaseProperty>(); Harvestable logOnHarvest = new Harvestable(); Log.Behaviours.Add(typeof(Harvestable), new Harvestable()); // -- MAN -- \\ Man = new EntitySchematic(); Man.RenderBasic = new RenderBasic(content.Load <Model>("Models/Entity/manmodel"), effect); Man.OccupiedSpace = new List <Vector3>(); Man.BaseScale = new Vector3(0.1f, 0.1f, 0.25f); Man.RenderOffset = new Vector3(0f, -0.15f, 0f); Man.Name = "Log"; Man.Description = "It's big, it's heavy, it's wood."; Man.Behaviours = new Dictionary <Type, BaseProperty>(); Harvestable ManOnHarvest = new Harvestable(); Man.Behaviours.Add(typeof(Harvestable), new Harvestable()); }
public virtual void MarkForHarvest() { if (CanBeHarvested()) { isMarkedForHarvest = true; Harvestable component = GetComponent <Harvestable>(); if ((UnityEngine.Object)component != (UnityEngine.Object)null) { component.OnMarkedForHarvest(); } } }
private void StateHarvesting() { // Play harvest sounds every x seconds HarvestSoundTimeRemaining -= Time.deltaTime; if (HarvestSoundTimeRemaining < 0.0f) { HarvestSoundTimeRemaining = HarvestSoundTime; GameObject.Find("Game").GetComponent <Game>().AudioManager.Play(HarvestTarget.GatherSound); } HarvestTimeRemaining -= Time.deltaTime; if (HarvestTimeRemaining <= 0.0f) { // Harvest tiles in a radius var game = GameObject.Find("Game").GetComponent <Game>(); var res = game.GetComponent <Game>().Resources; var environment = GameObject.Find("Environment").GetComponent <Environment>(); var tiles = environment.GetHarvestableTilesInRadius(HarvestTarget.GetComponent <EnvironmentTile>(), CurrentTool.HarvestRadius); int totalWood = 0, totalStone = 0; foreach (var t in tiles) { if (t.Type == EResource.Wood) { totalWood += t.Amount; } else if (t.Type == EResource.Stone) { totalStone += t.Amount; } environment.Harvest(t); } // Add total resources res.Wood += totalWood; res.Stone += totalStone; game.AudioManager.Play("Rubble"); // Reset states mAnimator.SetBool("IsHarvesting", false); State = EState.Idle; HarvestTarget = null; } }
private void DoActivity() { _currActivityInterval += Time.deltaTime; if (_currActivityInterval >= MaxActivityInterval) { _currActivityInterval -= MaxActivityInterval; Harvestable obj = Target.GetComponent <Harvestable>(); if (obj) { obj.HandleNPCInteract(this); } if (!Target) { _currQuestActivity = QuestActivity.needNewTarget; } } }
public void ExecuteHarvestTask(Vector3 position) { HarvestTarget = Task.HarvestTarget; if (HarvestTarget != null && !HarvestTarget.Equals(null)) { State = EState.Harvesting; HarvestTimeRemaining = CurrentTool.HarvestTime; Vector3 target = HarvestTarget.GetComponent <EnvironmentTile>().Position; transform.LookAt(new Vector3(target.x, position.y, target.z)); // Look at the tile we are harvesting mAnimator.SetBool("IsHarvesting", true); } else { HarvestTarget = null; } }
IEnumerator HarvestPrivate(Harvestable selected, Action OnDone) { if (selected is Critter) { OnHarvestCritterStart.Invoke(); GetComponentInChildren <SpriteRenderer>().flipX = transform.position.x > selected.transform.position.x; yield return(new WaitForSeconds(selected.durationOfHarvest)); OnHarvestCritterFinished.Invoke(); OnDone(); } else { OnHarvestStart.Invoke(); GetComponentInChildren <SpriteRenderer>().flipX = transform.position.x > selected.transform.position.x; yield return(new WaitForSeconds(selected.durationOfHarvest)); OnHarvestFinished.Invoke(); OnDone(); } }
public override void use() { Vector3 mousePosistion = Input.mousePosition; mousePosistion = Camera.main.ScreenToWorldPoint(mousePosistion); Vector2 rayStart = new Vector2(mousePosistion.x, mousePosistion.y); RaycastHit2D hit = Physics2D.Raycast(rayStart, Vector2.zero, 0f); if (hit.transform != null) { Harvestable resObj = hit.transform.GetComponent <Harvestable>(); if (resObj != null) { if (resObj.workable) { int quantity = resObj.work(Time.deltaTime); control.addItem(resObj.type, quantity); Debug.Log(string.Format("Harvested {0} from {1}", quantity, resObj.name)); return; } else { Debug.Log("harvestable. not workable"); return; } } Debug.Log("not harvestable"); return; } Debug.Log("nothing there"); return; }
public void Harvest(Harvestable selected, Action OnDone) { StartCoroutine(HarvestPrivate(selected, OnDone)); }
public static void Prefix(Harvestable __instance) { Debug.LogFormat("Harvestable::DoHarvest"); __instance.m_SecondsToHarvest = actionTime; }
public Harvest(TaskQueue queue, Harvestable harvestable) : base(queue, harvestable) { maxWorkers = 2; }
protected override void Update() { base.Update(); if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } if (health <= 0) { _isDead = true; } if (_isAiming) { aimInt = 1; } if (!_isAiming) { aimInt = 0; } animator.SetInteger("fireInt", fireInt); animator.SetInteger("aimInt", aimInt); animator.SetInteger("hasSnipped", hasSnipped); //when networking animations that require a button to be held use an int not a bool to control the animation!!! /*TEMP DISABLED TO FIX POSSIBLE CACHE * if (networkObject != null) * { * if (networkObject.IsOwner) * { * networkObject.fireInt = animator.GetInteger("fireInt"); * networkObject.aimInt = animator.GetInteger("aimInt"); * networkObject.hasSnipped = animator.GetInteger("hasSnipped"); * } * * if (!networkObject.IsOwner) * { * if (animator.GetInteger("fireInt") != networkObject.fireInt) * animator.SetInteger("fireInt", networkObject.fireInt); * * if (animator.GetInteger("aimInt") != networkObject.aimInt) * animator.SetInteger("aimInt", networkObject.aimInt); * * if (animator.GetInteger("hasSnipped") != networkObject.hasSnipped) * animator.SetInteger("hasSnipped", networkObject.hasSnipped); * } * } * * if (networkObject != null) * { * if (networkObject.IsOwner) * { * if(serverCam != null) * serverCam.enabled = false; * * _hudCanvas.SetActive(true); * camera.SetActive(true); * * if (UseChild) * { * networkObject.runningVal = animator.GetInteger("runningVal"); * networkObject.isJumping = animator.GetBool("isJumping"); * networkObject.onGround = animator.GetBool("onGround"); * networkObject.isThrowing = animator.GetBool("isThrowing"); * networkObject.horizontalVal = animator.GetInteger("horizontalVal"); * networkObject.hasSnipped = animator.GetInteger("hasSnipped"); * } * * networkObject.health = health; * networkObject.isDead = _isDead; * } * } * * if (networkObject != null && networkObject.IsOwner) * HealthCanvasMeter(); * * ThrowAttack(); * FireIntAttack(); * Aim(); * SnipAttack(); * * if (_startBaseCoolDown) CoolDown(); * * HudAttackMeter(_poisonReflillTransform, _poisonCoolDownTime);//For base attack, poison * HudAttackMeter(_fireReflillTransform, _fireCanvasVal);//For fire attacke * * * } * * protected override void FixedUpdate() * { * if (networkObject != null) * { * if (!networkObject.IsOwner) * { * transform.position = networkObject.position; * * if (!UseChild) * transform.rotation = networkObject.rotation; * * if(UseChild) * transform.GetChild(0).transform.rotation = networkObject.rotation; * * * if (UseChild) * { * if (animator.GetInteger("runningVal") != networkObject.runningVal) animator.SetInteger("runningVal", networkObject.runningVal); * if (animator.GetBool("isJumping") != networkObject.isJumping) animator.SetBool("isJumping", networkObject.isJumping); * if (animator.GetBool("onGround") != networkObject.onGround) animator.SetBool("onGround", networkObject.onGround); * if (animator.GetBool("isThrowing") != networkObject.isThrowing) animator.SetBool("isThrowing", networkObject.isThrowing); * if (animator.GetInteger("horizontalVal") != networkObject.horizontalVal) animator.SetInteger("horizontalVal", networkObject.horizontalVal); * } * * health = networkObject.health; * _isDead = networkObject.isDead; * * if (serverCam != null) * serverCam.enabled = true; * * _hudCanvas.SetActive(false); * camera.SetActive(false); * * return; * } * } * * /* * moveInput.Set(Input.GetAxisRaw("Horizontal"), * Input.GetButton("Jump") ? 1f : 0f, * Input.GetAxisRaw("Vertical")); */ base.FixedUpdate(); if (canPlant && isGrounded && groundCollider != null && groundCollider.GetComponent <DamageableEntity>() == null && Input.GetButton("Gather")) { if (GetComponent <Inventory>() != null) { Inventory inv = GetComponent <Inventory>(); RaycastHit hit; Item toPlant = inv.GetRandomPlantable(); if (toPlant != null && Physics.Raycast(transform.position, Vector3.down, out hit, 5f)) { Harvestable plant = Instantiate <Harvestable>(toPlant.plantPrefab, hit.point, Quaternion.Euler(0f, Random.value * 360f, 0f)); plant.canHarvest = false; plant.ForceUpdate(); inv.RemoveCountOfItemFromInventory(toPlant, 1); } } } if (networkObject != null) { networkObject.position = transform.position; if (!UseChild) { networkObject.rotation = transform.rotation; } if (UseChild) { networkObject.rotation = transform.GetChild(0).transform.rotation; } } }
new private void Harvest(Harvestable h) { ChangeState(states.harvesting); base.Harvest(h); }
public HarvestAction(Inventory i, Harvestable h) { inventory = i; harvestable = h; }
/// <summary> /// Applied before OnCompleteWork runs. /// </summary> internal static void Prefix(Harvestable __instance, Worker worker) { MarkDirection(__instance, worker); }
public void Harvest(Harvestable h) { man.Harvest(h); }
public void Harvest(Harvestable h) { queue.Enqueue(new HarvestAction(GetComponent <Inventory>(), h)); }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { targetHarvestable = animator.GetComponent <Citizen>().GetCurrentTarget().GetComponent <Harvestable>(); currentTimer = mineInterval; }
public override void InitializeStates(out BaseState default_state) { default_state = growing; base.serializable = true; growing.EventTransition(GameHashes.Wilt, stalled, (StatesInstance smi) => smi.IsWilting()).EventTransition(GameHashes.CropSleep, stalled, (StatesInstance smi) => smi.IsSleeping()).EventTransition(GameHashes.PlanterStorage, growing.planted, (StatesInstance smi) => smi.master.rm.Replanted) .EventTransition(GameHashes.PlanterStorage, growing.wild, (StatesInstance smi) => !smi.master.rm.Replanted) .TriggerOnEnter(GameHashes.Grow, null) .Update("CheckGrown", delegate(StatesInstance smi, float dt) { if (smi.ReachedNextHarvest()) { smi.GoTo(grown); } }, UpdateRate.SIM_4000ms, false) .ToggleStatusItem(Db.Get().CreatureStatusItems.Growing, (StatesInstance smi) => smi.master.GetComponent <Growing>()) .Enter(delegate(StatesInstance smi) { State state = (!smi.master.rm.Replanted) ? growing.wild : growing.planted; smi.GoTo(state); }); growing.wild.ToggleAttributeModifier("GrowingWild", (StatesInstance smi) => smi.wildGrowingRate, null); growing.planted.ToggleAttributeModifier("Growing", (StatesInstance smi) => smi.baseGrowingRate, null); stalled.EventTransition(GameHashes.WiltRecover, growing, (StatesInstance smi) => smi.CanExitStalled()).EventTransition(GameHashes.CropWakeUp, growing, (StatesInstance smi) => smi.CanExitStalled()); grown.DefaultState(grown.idle).TriggerOnEnter(GameHashes.Grow, null).Update("CheckNotGrown", delegate(StatesInstance smi, float dt) { if (!smi.ReachedNextHarvest()) { smi.GoTo(growing); } }, UpdateRate.SIM_4000ms, false) .ToggleAttributeModifier("GettingOld", (StatesInstance smi) => smi.getOldRate, null) .Enter(delegate(StatesInstance smi) { smi.ClampGrowthToHarvest(); }) .Exit(delegate(StatesInstance smi) { smi.master.oldAge.SetValue(0f); }); grown.idle.Update("CheckNotGrown", delegate(StatesInstance smi, float dt) { if (smi.master.shouldGrowOld && smi.master.oldAge.value >= smi.master.oldAge.GetMax()) { smi.GoTo(grown.try_self_harvest); } }, UpdateRate.SIM_4000ms, false); grown.try_self_harvest.Enter(delegate(StatesInstance smi) { Harvestable component = smi.master.GetComponent <Harvestable>(); if ((bool)component && component.CanBeHarvested) { bool harvestWhenReady = component.harvestDesignatable.HarvestWhenReady; component.ForceCancelHarvest(null); component.Harvest(); if (harvestWhenReady && (Object)component != (Object)null) { component.harvestDesignatable.SetHarvestWhenReady(true); } } smi.master.maturity.SetValue(0f); smi.master.oldAge.SetValue(0f); }).GoTo(grown.idle); }
protected override void GatherComponents() { base.GatherComponents(); harvestable = GetComponent <Harvestable>(); }