Esempio n. 1
0
        private static Item FindBestProjInRange(
            NPCPlayerApex.WeaponTypeEnum from,
            NPCPlayerApex.WeaponTypeEnum to,
            NPCHumanContext c)
        {
            Item           obj            = (Item)null;
            BaseProjectile baseProjectile = (BaseProjectile)null;

            foreach (Item allItem in c.Human.inventory.AllItems())
            {
                if (allItem.info.category == ItemCategory.Weapon && !allItem.isBroken)
                {
                    BaseProjectile heldEntity = allItem.GetHeldEntity() as BaseProjectile;
                    if (Object.op_Inequality((Object)heldEntity, (Object)null) && heldEntity.effectiveRangeType <= to && heldEntity.effectiveRangeType > from)
                    {
                        if (obj == null)
                        {
                            obj            = allItem;
                            baseProjectile = heldEntity;
                        }
                        else if ((double)heldEntity.hostileScore > (double)baseProjectile.hostileScore)
                        {
                            obj            = allItem;
                            baseProjectile = heldEntity;
                        }
                    }
                }
            }
            return(obj);
        }
        private static Item FindBestProjInRange(NPCPlayerApex.WeaponTypeEnum from, NPCPlayerApex.WeaponTypeEnum to, NPCHumanContext c)
        {
            Item           item           = null;
            BaseProjectile baseProjectile = null;

            Item[] itemArray = c.Human.inventory.AllItems();
            for (int i = 0; i < (int)itemArray.Length; i++)
            {
                Item item1 = itemArray[i];
                if (item1.info.category == ItemCategory.Weapon && !item1.isBroken)
                {
                    BaseProjectile heldEntity = item1.GetHeldEntity() as BaseProjectile;
                    if (heldEntity != null && heldEntity.effectiveRangeType <= to && heldEntity.effectiveRangeType > from)
                    {
                        if (item == null)
                        {
                            item           = item1;
                            baseProjectile = heldEntity;
                        }
                        else if (heldEntity.hostileScore > baseProjectile.hostileScore)
                        {
                            item           = item1;
                            baseProjectile = heldEntity;
                        }
                    }
                }
            }
            return(item);
        }
Esempio n. 3
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);
        }
        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);
        }