public virtual void GetDropped(EntityBody source) { if (PickedUp) { PickedUp = false; } }
void UpdateEnergy(EntityBody body) { energy = body.Energy; maxenergy = body.MaxEnergy; EnergyText.text = energy.ToString() + "/" + maxenergy.ToString(); }
//todo: actual eating public override IEnumerator Eat(EntityBody target) { if ((target.Position - Position).magnitude < GameManager.Instance.Config.MaxInteractionDistance && target.GetEaten(target)) { yield return(StartCoroutine(WaitWithProgress(0.1f))); RemoveFromEq(target); Energy += target.Energy; Health += target.Energy; if (Energy > MaxEnergy) { Energy = MaxEnergy; } if (Health > MaxHealth) { Health = MaxHealth; } target.OnDeath(); } else { yield return(StartCoroutine(WaitWithProgress(0.1f))); } }
public void Shoot(Vector2 targetLocation) { Vector2 direction = targetLocation - (Vector2)transform.position; transform.rotation = Quaternion.AngleAxis(Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg, Vector3.forward); EntityBody.AddForce(direction.normalized * weaponData.distancePerTimeUnit, ForceMode2D.Impulse); }
public float DistanceTo(EntityBody other) { float res = (transform.position - other.transform.position) .magnitude - Size - other.Size; return(res > 0 ? res : 0); }
void UpdateHP(EntityBody body) { hp = body.Health; maxhp = body.MaxHealth; HPText.text = hp.ToString() + "/" + maxhp.ToString(); }
public virtual bool GetPickedUp(EntityBody source) { if (PickedUp) { return(false); } return(PickedUp = true); }
public virtual void TakeHit(int damage, EntityBody source) { Health -= damage; if (Health <= 0) { OnDeath(); } }
void UpdateSelection(EntityBody body) { lastSelected = body; UpdateHP(body); UpdateEnergy(body); UpdateName(body); UpdateProgress(body as LivingEntityBody); }
public override IEnumerator PickUp(EntityBody target) { yield return(StartCoroutine(WaitWithProgress(0.1f))); if (target.GetPickedUp(this)) { Equipment.Add(target); target.transform.parent = transform; target.transform.localPosition = Vector3.up * 1 * (Equipment.Count + 1); } }
public bool WillAccept(EntityBody target) { ResourceBody b = target as ResourceBody; if (b == null) return false; if (b.Type == ResourceType.Food) return FoodInBank < FoodLimit; if (b.Type == ResourceType.Wood) return true; return false; }
// only Attack has a default implementation // the rest is pretty much only aplicable to Villagers public virtual IEnumerator Attack(EntityBody target) { //TODO: attack speed and damage based on stuff yield return(StartCoroutine(WaitWithProgress(AttackDuration))); if (target != null) { ProjectileBehaviour proj = Instantiate <ProjectileBehaviour>(GameManager.Instance.Projectile, transform.position, Quaternion.identity); proj.target = target.gameObject; target.TakeHit(AttackDamage, this); } }
// Update is called once per frame void Update() { EntityBody body = null; if (GameManager.Instance.SelectionController != null) { body = GameManager.Instance.SelectionController.Selected; } if (body) { if (!Background.activeSelf) { Background.SetActive(true); } if (body != lastSelected) { UpdateSelection(body); } if (energy != body.Energy || maxenergy != body.MaxEnergy) { UpdateEnergy(body); } if (hp != body.Health || maxhp != body.MaxHealth) { UpdateHP(body); } LivingEntityBody living = body as LivingEntityBody; if (living != null) { if (!ProgressBar.parent.gameObject.activeInHierarchy) { ProgressBar.parent.gameObject.SetActive(true); } UpdateProgress(living); } else if (ProgressBar.parent.gameObject.activeInHierarchy) { ProgressBar.parent.gameObject.SetActive(false); } } else if (Background.activeInHierarchy) { Background.SetActive(false); } }
public override IEnumerator Gather(EntityBody target) { //TODO: based on stats, equipment and the specific target // time should be modified // also, gathering range stuff Energy -= 3; ResourceNodeBody targetResource = target as ResourceNodeBody; if (targetResource != null && !targetResource.ResourceReady) { yield return(StartCoroutine(WaitWithProgress(1))); yield break; } float time = targetResource != null ? targetResource.BaseGatheringTime : 4; int timeMod = 5; switch (target.GenericName) { case EntityType.Tree: timeMod += Strength; if (Tool == ToolKind.Axe) { timeMod += ToolLevel; } else { Energy -= 4; } break; case EntityType.Lake: timeMod += Agility; if (Tool == ToolKind.Pole) { timeMod += ToolLevel; } else { Energy -= 4; } break; } time *= 5.0f / timeMod; yield return(StartCoroutine(WaitWithProgress(time))); target.GetGathered(this); }
public override IEnumerator Drop(EntityBody target) { if (Equipment.Contains(target) && target.PickedUp) { yield return(StartCoroutine(WaitWithProgress(0.1f))); RemoveFromEq(target); target.transform.parent = GameObject.FindGameObjectWithTag("Entities").transform; Vector3 mod = UnityEngine.Random.onUnitSphere; mod.y = 0; target.GetDropped(this); target.transform.position = transform.position + mod.normalized * 2; } yield return(StartCoroutine(WaitWithProgress(0.1f))); }
public void Operate() { if (ControlsManager.Instance != null && EntityManager.Instance != null) { if (Input.GetKeyDown(KeyCode.Mouse0) && ControlsManager.Instance.FocusNotOnConsole) { TrySelect(); } } if (Selected != null && !Selected.gameObject.activeInHierarchy) { Selected = null; } }
public bool WillAccept(EntityBody target) { ResourceBody b = target as ResourceBody; if (b == null) { return(false); } if (b.Type == ResourceType.Food) { return(FoodInBank < FoodLimit); } if (b.Type == ResourceType.Wood) { return(true); } return(false); }
public void MagazinePush(EntityBody target) { ResourceBody b = target as ResourceBody; if (b == null) return; if (b.Type == ResourceType.Food) FoodInBank++; if (b.Type == ResourceType.Wood) { WoodInBank++; if (WoodInBank == WoodLimit) { WoodInBank = 0; LevelUp(); } } b.OnDeath(); }
public void TrySelect() { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (!Physics.Raycast(ray, out hit, Mathf.Infinity, -1, QueryTriggerInteraction.Ignore)) { return; } if (!hit.collider || !hit.collider.transform) { MonoBehaviour.print("grabbed nothing"); return; } MonoBehaviour.print("grabbed " + hit.collider.gameObject); Selected = hit.collider.GetComponent <EntityBody>(); }
IEnumerator MagazinePush(VillageBody village, MagazinePush push) { EntityBody PushTarget = EntityManager.EntityHash[push.TargetID]; CurrentCommand = push; IsSneaking = false; yield return(WaitWithProgress(0.5f)); if (!Equipment.Contains(PushTarget)) { yield break; } if (!village.WillAccept(PushTarget)) { yield break; } RemoveFromEq(PushTarget); village.MagazinePush(PushTarget); CurrentCommand = null; }
public override void GetGathered(EntityBody source) { if (!ResourceReady) { return; } Vector3 sourcepos; if (source != null) { sourcepos = source.transform.position; } else { Vector3 rand = UnityEngine.Random.onUnitSphere; rand.y = 0; rand.Normalize(); sourcepos = transform.position + rand; } DropResources(DropCount, sourcepos); OnDeath(); }
void RemoveFromEq(EntityBody target) { if (!Equipment.Contains(target)) { return; } bool lower = false; foreach (EntityBody b in Equipment) { if (lower) { b.transform.localPosition += Vector3.down; } else if (b == target) { lower = true; } } Equipment.Remove(target); }
public void MagazinePush(EntityBody target) { ResourceBody b = target as ResourceBody; if (b == null) { throw new Exception("wat"); } if (b.Type == ResourceType.Food) { FoodInBank++; } if (b.Type == ResourceType.Wood) { WoodInBank++; if (WoodInBank == WoodLimit) { WoodInBank = 0; LevelUp(); } } b.OnDeath(); }
void UpdateName(EntityBody body) { NameText.text = body.Name.ToString(); IDText.text = body.EntityID.ToString(); }
public override bool GetPickedUp(EntityBody source) { return false; }
public override void GetGathered(EntityBody source) { }
public void Throw(Vector2 targetLocation) { AudioManager.Instance.Play("GrenadeThrow"); EntityBody.AddForce(Tools.CalculateVelocity(transform.position, targetLocation, (Mathf.Abs(transform.position.x - targetLocation.x) / weaponData.distancePerTimeUnit) + minTime), ForceMode2D.Impulse); }
public abstract void GetGathered(EntityBody source);
public virtual bool GetEaten(EntityBody source) { return(false); }
public override IEnumerator Gather(EntityBody target) { throw new NotImplementedException(); }