public override void DoAction(PlayerCharacter character, ItemSlot slot) { DigSpot spot = DigSpot.GetNearest(character.transform.position, dig_range); Plant plant = Plant.GetNearest(character.transform.position, dig_range); Vector3 pos = plant != null ? plant.transform.position : character.transform.position; if (spot != null) { pos = spot.transform.position; } string animation = character.Animation ? character.Animation.dig_anim : ""; character.TriggerAnim(animation, pos); character.TriggerProgressAction(1.5f, () => { if (spot != null) { spot.Dig(); } else if (plant != null) { plant.Kill(); } InventoryItemData ivdata = character.EquipData.GetItem(slot.index); if (ivdata != null) { ivdata.durability -= 1; } }); }
private IEnumerator DigRoutine() { yield return(new WaitForSeconds(1f)); if (action_target != null) { DigSpot dig = action_target.GetComponent <DigSpot>(); if (dig != null) { dig.Dig(); } } StopAction(); }
public static DigSpot GetNearest(Vector3 pos, float range = 999f) { DigSpot nearest = null; float min_dist = range; foreach (DigSpot spot in dig_list) { float dist = (spot.transform.position - pos).magnitude; if (dist < min_dist) { min_dist = dist; nearest = spot; } } return(nearest); }
public override void DoAction(PlayerCharacter character, Selectable select) { DigSpot spot = select.GetComponent <DigSpot>(); if (spot != null) { string animation = character.Animation ? character.Animation.dig_anim : ""; character.TriggerAnim(animation, spot.transform.position); character.TriggerProgressAction(1.5f, () => { spot.Dig(); InventoryItemData ivdata = character.EquipData.GetFirstItemInGroup(required_item); if (ivdata != null) { ivdata.durability -= 1; } }); } }
private void DetectAction() { if (PlayerIsFar(detect_range)) { return; } foreach (Selectable selectable in Selectable.GetAllActive()) { if (selectable.gameObject != gameObject) { Vector3 dir = (selectable.transform.position - transform.position); if (dir.magnitude < detect_range) { DigSpot dig = selectable.GetComponent <DigSpot>(); Destructible destruct = selectable.GetComponent <Destructible>(); if (can_attack && destruct && destruct.attack_group == AttackGroup.Enemy && destruct.required_item == null) { attack_target = destruct; action_target = null; character.Attack(destruct); ChangeState(PetState.Attack); return; } else if (can_dig && dig != null) { attack_target = null; action_target = dig.gameObject; ChangeState(PetState.Dig); character.MoveTo(dig.transform.position); return; } } } } }