/// <summary> /// Sets the target where an item is used at /// </summary> /// <param name="go"></param> public void SetTarget(GameObject go) { if (go.TryGetComponent <Creature>(out Creature target)) { this.target = target.Stats; } }
private void Awake() { statHandler = GetComponent <EntityStatHandler>(); inventory = GetComponent <InventoryManager>(); aMH = GameObject.Find("Game Manager").GetComponent <AdventureMenuHandler>(); playerControlled = GetComponent <EntityMovement>().playerControlled; }
private void Awake() { playerStats = GameObject.Find("objPlayer").GetComponent <EntityStatHandler>(); playerInventory = GameObject.Find("objPlayer").GetComponent <InventoryManager>(); floorManager = GameObject.Find("Game Manager").GetComponent <FloorManager>(); playerEntityManager = GameObject.Find("objPlayer").GetComponent <EntityManager>(); ChangeMenu(); }
private void OnTriggerStay2D(Collider2D collision) { if (collision.GetComponent <ItemScript>() != null && Vector3.Distance(collision.transform.position, transform.position) <= .1f && curEnergy >= 4) //Pick up an item { if (!collision.GetComponent <ItemScript>().Buyable) { if (inventory.AddItem(collision.GetComponent <ItemScript>())) { aMH.NewLogMessage(string.Format("{0} picked up {1}!", statHandler.entityName, collision.GetComponent <ItemScript>().Item.itemName)); Destroy(collision.gameObject); } } else { objOntopOf = collision.gameObject; } } if (transform.tag == "Player" && collision.tag == "Stairs" && Vector3.Distance(collision.transform.position, transform.position) <= .1f && curEnergy >= 4) { Debug.Log("Next Floor!"); GameObject.Find("Game Manager").GetComponent <FloorManager>().NextFloor(); } if (collision.GetComponent <WeaponHandler>() != null && Vector3.Distance(collision.transform.position, transform.position) <= .1f) { WeaponHandler weapon = collision.GetComponent <WeaponHandler>(); if (!weapon.IsThrown) { return; } if (weapon.parentObject == this.gameObject) { return; } EntityStatHandler statHandler = GetComponent <EntityStatHandler>(); EntityStatHandler eStatHandler = collision.GetComponent <WeaponHandler>().parentObject.GetComponent <EntityStatHandler>(); lastHitBy = collision.GetComponent <WeaponHandler>().parentObject; switch (weapon.ScaledStat) { case statType.strength: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Str, eStatHandler.Level); break; case statType.dexterity: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Dex, eStatHandler.Level); break; case statType.inteligence: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Intl, eStatHandler.Level); break; case statType.defense: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Def, eStatHandler.Level); break; } weapon.AttackFinished(); GetComponent <EntityAnimation>().isHurt = true; } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.GetComponent <WeaponHandler>() != null) { WeaponHandler weapon = collision.GetComponent <WeaponHandler>(); if (weapon.IsThrown) { return; } if (weapon.parentObject == this.gameObject) { return; } EntityStatHandler statHandler = GetComponent <EntityStatHandler>(); EntityStatHandler eStatHandler = collision.GetComponent <WeaponHandler>().parentObject.GetComponent <EntityStatHandler>(); lastHitBy = collision.GetComponent <WeaponHandler>().parentObject; switch (weapon.ScaledStat) { case statType.strength: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Str, eStatHandler.Level); break; case statType.dexterity: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Dex, eStatHandler.Level); break; case statType.inteligence: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Intl, eStatHandler.Level); break; case statType.defense: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Def, eStatHandler.Level); break; } GetComponent <EntityAnimation>().isHurt = true; } }
public void UpdateStats(EntityStatHandler source) { playerStats = TOOLS.CloneObject <List <Stat> >(source.StatList); }
//dont need this yet //public delegate void UseItemDelegate(Actor Target); //public UseItemDelegate UseItem; #region Monobehaviour Callbacks private void Start() { RefreshInventory(); target = TryGetComponent <Creature>(out Creature c)? c.Stats : null; }
public void Initialise() { // Add All Elements foreach (Element e in Enum.GetValues(typeof(Element))) { UnlockedElements = UnlockedElements.Add(e); } SpeechBubbleProxy = new EntitySpeechBubbleProxy(this); StatHandler = new EntityStatHandler(this); LevelHandler.Owner = this; SpellMarkers = new Dictionary<string, Timer>(); _audio = GetComponent<AudioSource>(); _updateSpeedTimer = new Timer(UnityEngine.Random.Range(0.15f, 0.35f)); EntityBehaviorTree = GetComponent<BehaviorTree>(); SpellCastTimer = new Timer(0f); foreach (var component in GetComponents<Component>()) { if (component is IPathFinder) { EntityPathFinder = component as IPathFinder; } } DeathController = GetComponent<DeathController>(); // Register health changed event for particles and such OnHealthChanged += HealthChanged; _audioPlayTimer = new Timer(0.25f); if (loadHealthBar) { HealthBar = Instantiate(GameMainReferences.Instance.GameConfigInfo.EntityHealthBarPrefab); HealthBar.Entity = this; HealthBar.gameObject.SetActive(true); // HealthBar.transform.SetParent(transform); } if (loadMinimapIcon) { var miniMapIcon = Instantiate(GameMainReferences.Instance.GameConfigInfo.EntityMinimapIcon); miniMapIcon.Entity = this; // Ensure it is active miniMapIcon.gameObject.SetActive(true); } _entityComponents = gameObject.GetComponents<EntityComponent>().ToList(); foreach (var comp in _entityComponents) { comp.Initialise(); } // TODO Figure out the animation system a bit better // For now all entities should have a HumanoidAnimatorController // on the base object EntityAnimator = GetComponent<HumanoidAnimatorController>(); ShouldTryEnableEntity = true; HasInitialised = true; }