public void OnDrop(PointerEventData eventData) { if (GameScene.SelectedCell != null) { Item = GameScene.SelectedCell; } GameScene.SelectedCell = null; GameScene.PickedUpGold = false; }
protected void OnWeaponChanged(IQuickSlotItem target) { if (base.hasAuthority && !isServerAuthoritative) { CmdWeaponChange(target.quickSlot); } if (m_ActiveWeapon != null) { if (m_ActiveWeapon is IThrownWeapon thrownWeapon) { OnThrownChange(thrownWeapon); } if (m_ActiveWeapon is IMeleeWeapon meleeWeapon) { OnMeleeChange(meleeWeapon); } if (m_ActiveWeapon is ModularFirearms.IModularFirearm fireWeapon) { OnFirearmChange(fireWeapon); } } m_ActiveWeapon = target.wieldable; if (m_ActiveWeapon != null) { if (base.hasAuthority) { m_ActiveWeapon.GetComponent <FpsInput>().enabled = true; } else { m_ActiveWeapon.GetComponent <FpsInput>().enabled = false; } if (m_ActiveWeapon is IThrownWeapon thrownWeapon) { OnThrownChange(thrownWeapon, true); } if (m_ActiveWeapon is IMeleeWeapon meleeWeapon) { OnMeleeChange(meleeWeapon, true); } if (m_ActiveWeapon is ModularFirearms.IModularFirearm fireWeapon) { OnFirearmChange(fireWeapon, true); } } }
//Called once per frame while the condition is active. //Return whether the condition is success or failure. protected override bool OnCheck() { IQuickSlotItem selected = agent.quickSlots.selected; m_Weapon = selected.GetComponent <IAiWeapon>(); bool isReady = HasWeaponEquipped(); isReady &= InSuitablePosition(); return(isReady); }
private void OnInventorySelectionChanged(IQuickSlotItem item) { if (item == null) { return; } ITrigger trigger = item.GetComponent <ITrigger>(); if (trigger != null) { if (currentTrigger != null) { currentTrigger.onShoot -= OnShoot; } currentTrigger = trigger; currentTrigger.onShoot += OnShoot; } }
//This is called once each time the task is enabled. //Call EndAction() to mark the action as finished, either in success or failure. //EndAction can be called from anywhere. protected override void OnExecute() { if (m_CooldownCompleteTime > Time.timeSinceLevelLoad) { EndAction(false); return; } if (stop.value && m_NavMeshAgent != null) { m_NavMeshAgent.isStopped = true; } IQuickSlotItem selected = agent.quickSlots.selected; m_Weapon = selected.GetComponent <IAiWeapon>(); originalAnimatorSpeed = m_Animator.speed; m_Animator.speed = attackSpeed.value; m_Animator.SetTrigger(AnimParams.ATTACK); m_CooldownCompleteTime = Time.timeSinceLevelLoad + m_Weapon.recoveryTime; }
//This is called once each time the task is enabled. //Call EndAction() to mark the action as finished, either in success or failure. //EndAction can be called from anywhere. protected override void OnExecute() { // TODO cache the inventory items and subscribe to changes // TODO don't consider changing weapon every cycle, only every x seconds int optimalSlot = -1; AiBaseWeapon optimalWeapon = null; float currentDeviationFromMidPoint = float.PositiveInfinity; for (int i = 0; i < agent.numSlots; i++) { IQuickSlotItem item = agent.GetSlotItem(i); if (item == null) { continue; } AiBaseWeapon weapon = item.GetComponent <AiBaseWeapon>(); if (optimalWeapon == null || (distanceToTarget.value >= weapon.minimumRange && distanceToTarget.value <= weapon.maximumRange)) { // TODO add a preference for higher damage weapons float deviation = Mathf.Abs(distanceToTarget.value - weapon.optimalRange); if (deviation < currentDeviationFromMidPoint) { // TODO add a penalty for changing weapons (that is only chang weapons when it is truly worthwhile) currentDeviationFromMidPoint = deviation; optimalSlot = i; optimalWeapon = weapon; } } } if (optimalWeapon != agent.selected.GetComponent <AiBaseWeapon>()) { agent.SelectSlot(optimalSlot); } EndAction(true); }
private void WieldableSelectionChanged(IQuickSlotItem item) { m_Weapon = item.gameObject.GetComponent <IAiWeapon>(); }