Example #1
0
        public static bool TrySwitchWeaponTo(NPCHumanContext c, NPCPlayerApex.WeaponTypeEnum WeaponType)
        {
            if (c != null && (double)Time.get_realtimeSinceStartup() >= (double)c.Human.NextWeaponSwitchTime)
            {
                uint svActiveItemId = c.Human.svActiveItemID;
                Item obj;
                switch (WeaponType)
                {
                case NPCPlayerApex.WeaponTypeEnum.CloseRange:
                    obj = SwitchWeaponOperator.FindBestMelee(c);
                    if (obj == null)
                    {
                        obj = SwitchWeaponOperator.FindBestProjInRange(NPCPlayerApex.WeaponTypeEnum.None, NPCPlayerApex.WeaponTypeEnum.CloseRange, c) ?? SwitchWeaponOperator.FindBestProjInRange(NPCPlayerApex.WeaponTypeEnum.CloseRange, NPCPlayerApex.WeaponTypeEnum.MediumRange, c) ?? SwitchWeaponOperator.FindBestProjInRange(NPCPlayerApex.WeaponTypeEnum.MediumRange, NPCPlayerApex.WeaponTypeEnum.LongRange, c);
                        c.Human.StoppingDistance = 2.5f;
                        break;
                    }
                    c.Human.StoppingDistance = 1.5f;
                    break;

                case NPCPlayerApex.WeaponTypeEnum.MediumRange:
                    obj = SwitchWeaponOperator.FindBestProjInRange(NPCPlayerApex.WeaponTypeEnum.CloseRange, NPCPlayerApex.WeaponTypeEnum.MediumRange, c) ?? SwitchWeaponOperator.FindBestProjInRange(NPCPlayerApex.WeaponTypeEnum.MediumRange, NPCPlayerApex.WeaponTypeEnum.LongRange, c);
                    c.Human.StoppingDistance = 0.1f;
                    break;

                case NPCPlayerApex.WeaponTypeEnum.LongRange:
                    obj = SwitchWeaponOperator.FindBestProjInRange(NPCPlayerApex.WeaponTypeEnum.MediumRange, NPCPlayerApex.WeaponTypeEnum.LongRange, c) ?? SwitchWeaponOperator.FindBestProjInRange(NPCPlayerApex.WeaponTypeEnum.CloseRange, NPCPlayerApex.WeaponTypeEnum.MediumRange, c);
                    c.Human.StoppingDistance = 0.1f;
                    break;

                default:
                    c.Human.UpdateActiveItem(0U);
                    if ((int)svActiveItemId != (int)c.Human.svActiveItemID)
                    {
                        c.Human.NextWeaponSwitchTime = Time.get_realtimeSinceStartup() + c.Human.WeaponSwitchFrequency;
                        c.SetFact(NPCPlayerApex.Facts.CurrentWeaponType, (byte)c.Human.GetCurrentWeaponTypeEnum(), true, true);
                        c.SetFact(NPCPlayerApex.Facts.CurrentAmmoState, (byte)c.Human.GetCurrentAmmoStateEnum(), true, true);
                    }
                    c.Human.StoppingDistance = 1f;
                    return(true);
                }
                if (obj != null)
                {
                    c.Human.UpdateActiveItem(obj.uid);
                    if ((int)svActiveItemId != (int)c.Human.svActiveItemID)
                    {
                        c.Human.NextWeaponSwitchTime = Time.get_realtimeSinceStartup() + c.Human.WeaponSwitchFrequency;
                        c.SetFact(NPCPlayerApex.Facts.CurrentWeaponType, (byte)c.Human.GetCurrentWeaponTypeEnum(), true, true);
                        c.SetFact(NPCPlayerApex.Facts.CurrentAmmoState, (byte)c.Human.GetCurrentAmmoStateEnum(), true, true);
                        c.SetFact(NPCPlayerApex.Facts.CurrentToolType, (byte)0, true, true);
                    }
                    return(true);
                }
            }
            return(false);
        }
Example #2
0
 public override void DoExecute(BaseContext c)
 {
     SwitchWeaponOperator.TrySwitchWeaponTo(c as NPCHumanContext, this.WeaponType);
 }
        public static bool TrySwitchWeaponTo(NPCHumanContext c, NPCPlayerApex.WeaponTypeEnum WeaponType)
        {
            Item item;

            if (c != null)
            {
                if (Time.realtimeSinceStartup < c.Human.NextWeaponSwitchTime)
                {
                    return(false);
                }
                uint human = c.Human.svActiveItemID;
                switch (WeaponType)
                {
                case NPCPlayerApex.WeaponTypeEnum.CloseRange:
                {
                    item = SwitchWeaponOperator.FindBestMelee(c);
                    if (item != null)
                    {
                        c.Human.StoppingDistance = 1.5f;
                        break;
                    }
                    else
                    {
                        item = SwitchWeaponOperator.FindBestProjInRange(NPCPlayerApex.WeaponTypeEnum.None, NPCPlayerApex.WeaponTypeEnum.CloseRange, c) ?? (SwitchWeaponOperator.FindBestProjInRange(NPCPlayerApex.WeaponTypeEnum.CloseRange, NPCPlayerApex.WeaponTypeEnum.MediumRange, c) ?? SwitchWeaponOperator.FindBestProjInRange(NPCPlayerApex.WeaponTypeEnum.MediumRange, NPCPlayerApex.WeaponTypeEnum.LongRange, c));
                        c.Human.StoppingDistance = 2.5f;
                        break;
                    }
                }

                case NPCPlayerApex.WeaponTypeEnum.MediumRange:
                {
                    item = SwitchWeaponOperator.FindBestProjInRange(NPCPlayerApex.WeaponTypeEnum.CloseRange, NPCPlayerApex.WeaponTypeEnum.MediumRange, c) ?? SwitchWeaponOperator.FindBestProjInRange(NPCPlayerApex.WeaponTypeEnum.MediumRange, NPCPlayerApex.WeaponTypeEnum.LongRange, c);
                    c.Human.StoppingDistance = 0.1f;
                    break;
                }

                case NPCPlayerApex.WeaponTypeEnum.LongRange:
                {
                    item = SwitchWeaponOperator.FindBestProjInRange(NPCPlayerApex.WeaponTypeEnum.MediumRange, NPCPlayerApex.WeaponTypeEnum.LongRange, c) ?? SwitchWeaponOperator.FindBestProjInRange(NPCPlayerApex.WeaponTypeEnum.CloseRange, NPCPlayerApex.WeaponTypeEnum.MediumRange, c);
                    c.Human.StoppingDistance = 0.1f;
                    break;
                }

                default:
                {
                    c.Human.UpdateActiveItem(0);
                    if (human != c.Human.svActiveItemID)
                    {
                        c.Human.NextWeaponSwitchTime = Time.realtimeSinceStartup + c.Human.WeaponSwitchFrequency;
                        c.SetFact(NPCPlayerApex.Facts.CurrentWeaponType, (byte)c.Human.GetCurrentWeaponTypeEnum(), true, true);
                        c.SetFact(NPCPlayerApex.Facts.CurrentAmmoState, (byte)c.Human.GetCurrentAmmoStateEnum(), true, true);
                    }
                    c.Human.StoppingDistance = 1f;
                    return(true);
                }
                }
                if (item != null)
                {
                    c.Human.UpdateActiveItem(item.uid);
                    if (human != c.Human.svActiveItemID)
                    {
                        c.Human.NextWeaponSwitchTime = Time.realtimeSinceStartup + c.Human.WeaponSwitchFrequency;
                        c.SetFact(NPCPlayerApex.Facts.CurrentWeaponType, (byte)c.Human.GetCurrentWeaponTypeEnum(), true, true);
                        c.SetFact(NPCPlayerApex.Facts.CurrentAmmoState, (byte)c.Human.GetCurrentAmmoStateEnum(), true, true);
                        c.SetFact(NPCPlayerApex.Facts.CurrentToolType, 0, true, true);
                    }
                    return(true);
                }
            }
            return(false);
        }