Exemple #1
0
        private void UpdateCollisionSpheres(Vec3 position, Vec3 velocity, ItemObject missileItem)
        {
            MissionWeapon missionWeapon = new MissionWeapon(missileItem, (ItemModifier)null, (Banner)null);
            Vec3          vec3_1        = velocity;
            double        num1          = (double)vec3_1.Normalize();
            Vec3          va            = vec3_1;
            double        num2          = (double)va.Normalize();
            float         x             = va.x;
            float         y             = va.y;
            float         z             = va.z;
            float         num3          = (float)((double)x * (double)position.x + (double)y * (double)position.y + (double)z * (double)position.z);
            Vec3          vb            = new Vec3(1f, 1f);
            float         num4          = (double)Math.Abs(z - 0.0f) < 1.40129846432482E-45 ? 1f : z;

            vb.z = (float)(-(double)num3 - (double)x * (1.0 - (double)position.x) - (double)y * (1.0 - (double)position.y) + (double)num4 * (double)position.z) / num4;
            double num5   = (double)vb.Normalize();
            Vec3   vec3_2 = Vec3.CrossProduct(va, vb);
            double num6   = (double)vec3_2.Normalize();

            Vec3[] vec3Array = new Vec3[0];
            for (int index = 0; index < 0; ++index)
            {
                float num7 = (float)((double)index * 360.0 / 0.0 * 3.14159274101257 / 180.0);
                vec3Array[index] = va + vb * (float)Math.Sin((double)num7) * 0.1f + vec3_2 * (float)Math.Cos((double)num7) * 0.1f;
            }
            for (int index = 0; index < vec3Array.Length; ++index)
            {
                Vec3        missileDirection      = vec3Array[index];
                WeaponData  weaponData            = missionWeapon.GetWeaponData(false);
                Vec3        missileCollisionPoint = Mission.Current.GetMissileCollisionPoint(position, missileDirection, velocity.Length, in weaponData);
                MatrixFrame frame = this.collisionEntity[index].GetFrame();
                frame.origin = missileCollisionPoint;
                this.collisionEntity[index].SetFrame(ref frame);
            }
        }
Exemple #2
0
        public static void WriteWeaponReferenceToPacket(MissionWeapon weapon)
        {
            GameNetworkMessage.WriteBoolToPacket(weapon.IsEmpty);
            if (weapon.IsEmpty)
            {
                return;
            }
            GameNetworkMessage.WriteObjectReferenceToPacket((MBObjectBase)weapon.Item, CompressionBasic.GUIDCompressionInfo);
            GameNetworkMessage.WriteIntToPacket((int)weapon.RawDataForNetwork, CompressionGeneric.ItemDataValueCompressionInfo);
            GameNetworkMessage.WriteIntToPacket((int)weapon.ReloadPhase, CompressionMission.WeaponReloadPhaseCompressionInfo);
            GameNetworkMessage.WriteIntToPacket(weapon.CurrentUsageIndex, CompressionMission.WeaponUsageIndexCompressionInfo);
            int num1 = weapon.Banner != null ? 1 : 0;

            GameNetworkMessage.WriteBoolToPacket(num1 != 0);
            if (num1 != 0)
            {
                GameNetworkMessage.WriteStringToPacket(weapon.Banner.Serialize());
            }
            MissionWeapon ammoWeapon = weapon.AmmoWeapon;
            int           num2       = !ammoWeapon.IsEmpty ? 1 : 0;

            GameNetworkMessage.WriteBoolToPacket(num2 != 0);
            if (num2 == 0)
            {
                return;
            }
            GameNetworkMessage.WriteObjectReferenceToPacket((MBObjectBase)ammoWeapon.Item, CompressionBasic.GUIDCompressionInfo);
            GameNetworkMessage.WriteIntToPacket((int)ammoWeapon.RawDataForNetwork, CompressionGeneric.ItemDataValueCompressionInfo);
        }
Exemple #3
0
 protected internal override void OnWeaponDrop(MissionWeapon droppedWeapon)
 {
     if (droppedWeapon.IsEmpty || droppedWeapon.Item.ItemType != ItemObject.ItemTypeEnum.Banner)
     {
         return;
     }
     MPPerkObject.GetPerkHandler(this.Agent)?.OnEvent(MPPerkCondition.PerkEventFlags.BannerDrop);
 }
Exemple #4
0
 private bool IsAnyConsumableDepleted()
 {
     for (EquipmentIndex index = EquipmentIndex.WeaponItemBeginSlot; index < EquipmentIndex.Weapon4; ++index)
     {
         MissionWeapon missionWeapon = this.Agent.Equipment[index];
         if (!missionWeapon.IsEmpty && missionWeapon.IsAnyConsumable(out WeaponComponentData _) && missionWeapon.Amount == (short)0)
         {
             return(true);
         }
     }
     return(false);
 }
        public static GameEntity Instantiate(
            Scene scene,
            MissionWeapon weapon,
            bool showHolsterWithWeapon,
            bool needBatchedVersion)
        {
            WeaponData weaponData = weapon.GetWeaponData(needBatchedVersion);

            WeaponStatsData[] weaponStatsData = weapon.GetWeaponStatsData();
            WeaponData        ammoWeaponData  = weapon.GetAmmoWeaponData(needBatchedVersion);

            WeaponStatsData[] ammoWeaponStatsData = weapon.GetAmmoWeaponStatsData();
            GameEntity        fromWeapon          = MBAPI.IMBGameEntityExtensions.CreateFromWeapon(scene.Pointer, in weaponData, weaponStatsData, weaponStatsData.Length, in ammoWeaponData, ammoWeaponStatsData, ammoWeaponStatsData.Length, showHolsterWithWeapon);

            weaponData.DeinitializeManagedPointers();
            return(fromWeapon);
        }
Exemple #6
0
        public SpawnedItemEntity SelectPickableItem(Vec3 bMin, Vec3 bMax)
        {
            Agent             targetAgent       = this.Agent.GetTargetAgent();
            Vec3              v1                = targetAgent == null ? Vec3.Invalid : targetAgent.Position - this.Agent.Position;
            int               num1              = this.Agent.Mission.Scene.SelectEntitiesInBoxWithScriptComponent <SpawnedItemEntity>(ref bMin, ref bMax, this._tempPickableEntities, this._pickableItemsId);
            float             num2              = 0.0f;
            SpawnedItemEntity spawnedItemEntity = (SpawnedItemEntity)null;

            for (int index = 0; index < num1; ++index)
            {
                SpawnedItemEntity firstScriptOfType = this._tempPickableEntities[index].GetFirstScriptOfType <SpawnedItemEntity>();
                int num3;
                if (firstScriptOfType != null)
                {
                    MissionWeapon weaponCopy = firstScriptOfType.WeaponCopy;
                    if (!weaponCopy.IsEmpty)
                    {
                        weaponCopy = firstScriptOfType.WeaponCopy;
                        num3       = weaponCopy.IsShield() || firstScriptOfType.IsStuckMissile() ? 1 : (firstScriptOfType.IsQuiverAndNotEmpty() ? 1 : 0);
                        goto label_5;
                    }
                }
                num3 = 0;
label_5:
                if (num3 != 0 && !firstScriptOfType.HasUser && (firstScriptOfType.MovingAgents.Count == 0 || firstScriptOfType.MovingAgents.ContainsKey(this.Agent)) && firstScriptOfType.GameEntityWithWorldPosition.WorldPosition.GetNavMesh() != UIntPtr.Zero)
                {
                    Vec3   v2   = firstScriptOfType.GetUserFrameForAgent(this.Agent).Origin.Position - this.Agent.Position;
                    double num4 = (double)v2.Normalize();
                    if (targetAgent == null || (double)v1.Length - (double)Vec3.DotProduct(v1, v2) > (double)targetAgent.MaximumForwardUnlimitedSpeed * 3.0)
                    {
                        EquipmentIndex slotToPickUp  = MissionEquipment.SelectWeaponPickUpSlot(this.Agent, firstScriptOfType.WeaponCopy, firstScriptOfType.IsStuckMissile());
                        WorldPosition  worldPosition = firstScriptOfType.GameEntityWithWorldPosition.WorldPosition;
                        if (slotToPickUp != EquipmentIndex.None && worldPosition.GetNavMesh() != UIntPtr.Zero && (this.IsItemAvailable(firstScriptOfType, slotToPickUp) && this.Agent.CanMoveDirectlyToPosition(in worldPosition)))
                        {
                            float itemScore = this.GetItemScore(firstScriptOfType);
                            if ((double)itemScore > (double)num2)
                            {
                                spawnedItemEntity = firstScriptOfType;
                                num2 = itemScore;
                            }
                        }
                    }
                }
            }
            return(spawnedItemEntity);
        }
Exemple #7
0
        private bool IsItemAvailable(SpawnedItemEntity item, EquipmentIndex slotToPickUp)
        {
            if (!this.Agent.CanReachAndUseObject((UsableMissionObject)item, 0.0f) || !this.Agent.ObjectHasVacantPosition((UsableMissionObject)item) || item.MovingAgents.Count > 0)
            {
                return(false);
            }
            WeaponClass weaponClass = item.WeaponCopy.Item.PrimaryWeapon.WeaponClass;

            switch (weaponClass)
            {
            case WeaponClass.Arrow:
            case WeaponClass.Bolt:
            case WeaponClass.ThrowingAxe:
            case WeaponClass.ThrowingKnife:
            case WeaponClass.Javelin:
                if (item.WeaponCopy.Amount > (short)0)
                {
                    MissionWeapon missionWeapon = this.Agent.Equipment[slotToPickUp];
                    if (!missionWeapon.IsEmpty)
                    {
                        missionWeapon = this.Agent.Equipment[slotToPickUp];
                        if (missionWeapon.Item.PrimaryWeapon.WeaponClass == weaponClass)
                        {
                            missionWeapon = this.Agent.Equipment[slotToPickUp];
                            int amount = (int)missionWeapon.Amount;
                            missionWeapon = this.Agent.Equipment[slotToPickUp];
                            int num = (int)missionWeapon.ModifiedMaxAmount >> 1;
                            if (amount <= num)
                            {
                                return(true);
                            }
                            break;
                        }
                        break;
                    }
                    break;
                }
                break;

            case WeaponClass.SmallShield:
            case WeaponClass.LargeShield:
                return(this.Agent.Equipment[slotToPickUp].IsEmpty && this._shieldIsBroken);
            }
            return(false);
        }
Exemple #8
0
        public void SpawnWeapon()
        {
            this.OnPreInit();
            this.GameEntity.RemoveAllChildren();
            MissionWeapon weapon     = new MissionWeapon(MBObjectManager.Instance.GetObject <ItemObject>(this.GameEntity.Name), (ItemModifier)null, (Banner)null);
            GameEntity    gameEntity = Mission.Current.SpawnWeaponWithNewEntity(ref weapon, Mission.WeaponSpawnFlags.WithPhysics, this.GameEntity.GetGlobalFrame());
            List <string> stringList = new List <string>();

            foreach (string tag in this.GameEntity.Tags)
            {
                gameEntity.AddTag(tag);
                stringList.Add(tag);
            }
            for (int index = 0; index < stringList.Count; ++index)
            {
                this.GameEntity.RemoveTag(stringList[index]);
            }
        }
Exemple #9
0
 private bool CheckEquipmentForAgentForPickUpAvailability()
 {
     if (this._disablePickUpForAgent)
     {
         return(false);
     }
     if (this._shieldIsBroken)
     {
         return(true);
     }
     for (EquipmentIndex index = EquipmentIndex.WeaponItemBeginSlot; index < EquipmentIndex.Weapon4; ++index)
     {
         MissionWeapon missionWeapon = this.Agent.Equipment[index];
         if (!missionWeapon.IsEmpty && missionWeapon.IsAnyConsumable(out WeaponComponentData _) && (int)missionWeapon.Amount <= (int)missionWeapon.ModifiedMaxAmount >> 1)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #10
0
        public static MissionWeapon ReadWeaponReferenceFromPacket(
            MBObjectManager objectManager,
            ref bool bufferReadValid)
        {
            if (GameNetworkMessage.ReadBoolFromPacket(ref bufferReadValid))
            {
                return(MissionWeapon.Invalid);
            }
            MBObjectBase mbObjectBase1 = GameNetworkMessage.ReadObjectReferenceFromPacket(objectManager, CompressionBasic.GUIDCompressionInfo, ref bufferReadValid);
            int          num1          = GameNetworkMessage.ReadIntFromPacket(CompressionGeneric.ItemDataValueCompressionInfo, ref bufferReadValid);
            int          num2          = GameNetworkMessage.ReadIntFromPacket(CompressionMission.WeaponReloadPhaseCompressionInfo, ref bufferReadValid);
            short        num3          = (short)GameNetworkMessage.ReadIntFromPacket(CompressionMission.WeaponUsageIndexCompressionInfo, ref bufferReadValid);
            int          num4          = GameNetworkMessage.ReadBoolFromPacket(ref bufferReadValid) ? 1 : 0;
            Banner       banner        = (Banner)null;

            if (num4 != 0)
            {
                string bannerKey = GameNetworkMessage.ReadStringFromPacket(ref bufferReadValid);
                if (bufferReadValid)
                {
                    banner = new Banner(bannerKey);
                }
            }
            ItemObject    primaryItem1 = mbObjectBase1 as ItemObject;
            bool          flag         = GameNetworkMessage.ReadBoolFromPacket(ref bufferReadValid);
            MissionWeapon missionWeapon;

            if (bufferReadValid & flag)
            {
                MBObjectBase mbObjectBase2 = GameNetworkMessage.ReadObjectReferenceFromPacket(objectManager, CompressionBasic.GUIDCompressionInfo, ref bufferReadValid);
                int          num5          = GameNetworkMessage.ReadIntFromPacket(CompressionGeneric.ItemDataValueCompressionInfo, ref bufferReadValid);
                ItemObject   primaryItem2  = mbObjectBase2 as ItemObject;
                missionWeapon = new MissionWeapon(primaryItem1, (ItemModifier)null, banner, (short)num1, (short)num2, new MissionWeapon?(new MissionWeapon(primaryItem2, (ItemModifier)null, banner, (short)num5)));
            }
            else
            {
                missionWeapon = new MissionWeapon(primaryItem1, (ItemModifier)null, banner, (short)num1, (short)num2, new MissionWeapon?());
            }
            missionWeapon.CurrentUsageIndex = (int)num3;
            return(missionWeapon);
        }
Exemple #11
0
 private void DisablePickUpForAgentIfNeeded()
 {
     this._disablePickUpForAgent = true;
     if (this.Agent.MountAgent != null)
     {
         return;
     }
     if (this._shieldIsBroken)
     {
         this._disablePickUpForAgent = false;
     }
     else
     {
         for (EquipmentIndex index = EquipmentIndex.WeaponItemBeginSlot; index < EquipmentIndex.Weapon4; ++index)
         {
             MissionWeapon missionWeapon = this.Agent.Equipment[index];
             if (!missionWeapon.IsEmpty && missionWeapon.IsAnyConsumable(out WeaponComponentData _))
             {
                 this._disablePickUpForAgent = false;
                 break;
             }
         }
     }
 }
Exemple #12
0
 protected internal override void OnTick(float dt)
 {
     if (!this._isVisible)
     {
         return;
     }
     base.OnTick(dt);
     if (GameNetwork.IsClientOrReplay)
     {
         return;
     }
     foreach (StandingPoint standingPoint in this.StandingPoints)
     {
         if (standingPoint.HasUser)
         {
             Agent            userAgent      = standingPoint.UserAgent;
             ActionIndexCache currentAction1 = userAgent.GetCurrentAction(0);
             ActionIndexCache currentAction2 = userAgent.GetCurrentAction(1);
             if (!(currentAction2 == ActionIndexCache.act_none) || !(currentAction1 == ArrowBarrel.act_pickup_down_begin) && !(currentAction1 == ArrowBarrel.act_pickup_down_begin_left_stance))
             {
                 if (currentAction2 == ActionIndexCache.act_none && (currentAction1 == ArrowBarrel.act_pickup_down_end || currentAction1 == ArrowBarrel.act_pickup_down_end_left_stance))
                 {
                     for (EquipmentIndex index = EquipmentIndex.WeaponItemBeginSlot; index < EquipmentIndex.NumAllWeaponSlots; ++index)
                     {
                         MissionWeapon missionWeapon = userAgent.Equipment[index];
                         if (!missionWeapon.IsEmpty)
                         {
                             missionWeapon = userAgent.Equipment[index];
                             if (missionWeapon.CurrentUsageItem.WeaponClass != WeaponClass.Arrow)
                             {
                                 missionWeapon = userAgent.Equipment[index];
                                 if (missionWeapon.CurrentUsageItem.WeaponClass != WeaponClass.Bolt)
                                 {
                                     continue;
                                 }
                             }
                             missionWeapon = userAgent.Equipment[index];
                             int amount = (int)missionWeapon.Amount;
                             missionWeapon = userAgent.Equipment[index];
                             int modifiedMaxAmount1 = (int)missionWeapon.ModifiedMaxAmount;
                             if (amount < modifiedMaxAmount1)
                             {
                                 Agent agent = userAgent;
                                 int   num   = (int)index;
                                 missionWeapon = userAgent.Equipment[index];
                                 int modifiedMaxAmount2 = (int)missionWeapon.ModifiedMaxAmount;
                                 agent.SetWeaponAmountInSlot((EquipmentIndex)num, (short)modifiedMaxAmount2, true);
                                 Mission.Current.MakeSoundOnlyOnRelatedPeer(ArrowBarrel._pickupArrowSoundFromBarrelCache, userAgent.Position, userAgent.Index);
                             }
                         }
                     }
                     userAgent.StopUsingGameObject();
                 }
                 else if (currentAction2 != ActionIndexCache.act_none || !userAgent.SetActionChannel(0, userAgent.GetIsLeftStance() ? ArrowBarrel.act_pickup_down_begin_left_stance : ArrowBarrel.act_pickup_down_begin))
                 {
                     userAgent.StopUsingGameObject();
                 }
             }
         }
     }
 }
        protected internal override void OnTick(float dt)
        {
            base.OnTick(dt);
            if (!this.GameEntity.IsVisibleIncludeParents())
            {
                return;
            }
            if (this.State == RangedSiegeWeapon.WeaponState.WaitingBeforeProjectileLeaving)
            {
                this.UpdateProjectilePosition();
            }
            if ((NativeObject)this._verticalAdjuster.Skeleton != (NativeObject)null)
            {
                this._verticalAdjuster.Skeleton.SetAnimationParameterAtChannel(0, (float)(((double)this.currentReleaseAngle - (double)this.BottomReleaseAngleRestriction) / ((double)this.TopReleaseAngleRestriction - (double)this.BottomReleaseAngleRestriction)));
            }
            MatrixFrame parent = this.SkeletonOwnerObjects[0].GameEntity.GetBoneEntitialFrameWithIndex((byte)0).TransformToParent(this._verticalAdjusterStartingLocalFrame);

            this._verticalAdjuster.SetFrame(ref parent);
            MatrixFrame globalFrame = this._body.GameEntity.GetGlobalFrame();

            for (int index = 0; index < this.StandingPoints.Count; ++index)
            {
                if (this.StandingPoints[index].HasUser)
                {
                    if (MBMath.IsBetween((int)this.StandingPoints[index].UserAgent.GetCurrentActionType(0), 44, 48))
                    {
                        this.StandingPoints[index].UserAgent.ClearHandInverseKinematics();
                    }
                    else if (this.StandingPoints[index] != this.PilotStandingPoint)
                    {
                        if (this.StandingPoints[index].UserAgent.GetCurrentAction(1) != this._reload2IdleActionIndex)
                        {
                            this.StandingPoints[index].UserAgent.SetHandInverseKinematicsFrameFromActionChannel(1, this._standingPointLocalIKFrames[index], globalFrame);
                        }
                        else
                        {
                            this.StandingPoints[index].UserAgent.ClearHandInverseKinematics();
                        }
                    }
                    else
                    {
                        this.StandingPoints[index].UserAgent.SetHandInverseKinematicsFrameFromActionChannel(1, this._standingPointLocalIKFrames[index], globalFrame);
                    }
                }
            }
            if (!GameNetwork.IsClientOrReplay)
            {
                for (int index = 0; index < this._rotateStandingPoints.Count; ++index)
                {
                    StandingPoint rotateStandingPoint = this._rotateStandingPoints[index];
                    if (rotateStandingPoint.HasUser && !rotateStandingPoint.UserAgent.SetActionChannel(1, index == 0 ? this._rotateLeftAnimationActionIndex : this._rotateRightAnimationActionIndex))
                    {
                        rotateStandingPoint.UserAgent.StopUsingGameObject();
                    }
                }
                if (this.PilotAgent != null)
                {
                    ActionIndexCache currentAction = this.PilotAgent.GetCurrentAction(1);
                    if (this.State == RangedSiegeWeapon.WeaponState.WaitingBeforeProjectileLeaving)
                    {
                        if (MBMath.IsBetween((int)this.PilotAgent.GetCurrentActionType(0), 44, 48))
                        {
                            if (this.PilotAgent.GetCurrentAction(0) != Mangonel.act_strike_bent_over)
                            {
                                this.PilotAgent.SetActionChannel(0, Mangonel.act_strike_bent_over);
                            }
                        }
                        else if (!this.PilotAgent.SetActionChannel(1, this._shootAnimationActionIndex))
                        {
                            this.PilotAgent.StopUsingGameObject();
                        }
                    }
                    else if (!this.PilotAgent.SetActionChannel(1, this._idleAnimationActionIndex) && currentAction != this._reload1AnimationActionIndex && currentAction != this._shootAnimationActionIndex)
                    {
                        this.PilotAgent.StopUsingGameObject();
                    }
                }
                if (this._reloadWithoutPilot.HasUser)
                {
                    Agent userAgent = this._reloadWithoutPilot.UserAgent;
                    if (!userAgent.SetActionChannel(1, this._reload2IdleActionIndex) && userAgent.GetCurrentAction(1) != this._reload2AnimationActionIndex)
                    {
                        userAgent.StopUsingGameObject();
                    }
                }
                foreach (StandingPointWithWeaponRequirement pickUpStandingPoint in this.AmmoPickUpStandingPoints)
                {
                    if (pickUpStandingPoint.HasUser)
                    {
                        Agent            userAgent     = pickUpStandingPoint.UserAgent;
                        ActionIndexCache currentAction = userAgent.GetCurrentAction(1);
                        if (!(currentAction == Mangonel.act_pickup_boulder_begin))
                        {
                            if (currentAction == Mangonel.act_pickup_boulder_end)
                            {
                                MissionWeapon weapon = new MissionWeapon(this.OriginalMissileItem, (ItemModifier)null, (Banner)null, (short)1);
                                userAgent.EquipWeaponToExtraSlotAndWield(ref weapon);
                                userAgent.StopUsingGameObject();
                                this.ConsumeAmmo();
                                if (!this.IsDeactivated && !this.LoadAmmoStandingPoint.HasUser && (!this.LoadAmmoStandingPoint.HasAIMovingTo && this.HasAIPickingUpAmmo) && this.CurrentlyUsedAmmoPickUpPoint == pickUpStandingPoint)
                                {
                                    this.LoadAmmoStandingPoint.SetIsDeactivatedSynched(false);
                                    if (userAgent.IsAIControlled)
                                    {
                                        StandingPoint standingPointFor = this.GetSuitableStandingPointFor(this.Side, userAgent);
                                        if (standingPointFor != null)
                                        {
                                            ((IDetachment)this).AddAgent(userAgent);
                                            if (userAgent.Formation != null)
                                            {
                                                userAgent.Formation.DetachUnit(userAgent, this.IsLoose);
                                                userAgent.Detachment       = (IDetachment)this;
                                                userAgent.DetachmentWeight = this.GetWeightOfStandingPoint(standingPointFor);
                                            }
                                        }
                                    }
                                }
                            }
                            else if (!userAgent.SetActionChannel(1, Mangonel.act_pickup_boulder_begin))
                            {
                                userAgent.StopUsingGameObject();
                            }
                        }
                    }
                }
            }
            switch (this.State)
            {
            case RangedSiegeWeapon.WeaponState.LoadingAmmo:
                if (GameNetwork.IsClientOrReplay || !this.LoadAmmoStandingPoint.HasUser)
                {
                    break;
                }
                Agent userAgent1 = this.LoadAmmoStandingPoint.UserAgent;
                if (userAgent1.GetCurrentAction(1) == this._loadAmmoEndAnimationActionIndex)
                {
                    EquipmentIndex wieldedItemIndex = userAgent1.GetWieldedItemIndex(Agent.HandIndex.MainHand);
                    if (wieldedItemIndex != EquipmentIndex.None && userAgent1.Equipment[wieldedItemIndex].CurrentUsageItem.WeaponClass == this.OriginalMissileItem.PrimaryWeapon.WeaponClass)
                    {
                        this.ChangeProjectileEntityServer(userAgent1, userAgent1.Equipment[wieldedItemIndex].Item.StringId);
                        userAgent1.RemoveEquippedWeapon(wieldedItemIndex);
                        this._timeElapsedAfterLoading = 0.0f;
                        this.Projectile.SetVisibleSynched(true);
                        this.State = RangedSiegeWeapon.WeaponState.WaitingBeforeIdle;
                        break;
                    }
                    this.LoadAmmoStandingPoint.UserAgent.StopUsingGameObject();
                    break;
                }
                if (!(userAgent1.GetCurrentAction(1) != this._loadAmmoBeginAnimationActionIndex) || this.LoadAmmoStandingPoint.UserAgent.SetActionChannel(1, this._loadAmmoBeginAnimationActionIndex))
                {
                    break;
                }
                for (EquipmentIndex equipmentIndex = EquipmentIndex.WeaponItemBeginSlot; equipmentIndex < EquipmentIndex.NumAllWeaponSlots; ++equipmentIndex)
                {
                    if (!userAgent1.Equipment[equipmentIndex].IsEmpty && userAgent1.Equipment[equipmentIndex].CurrentUsageItem.WeaponClass == this.OriginalMissileItem.PrimaryWeapon.WeaponClass)
                    {
                        userAgent1.RemoveEquippedWeapon(equipmentIndex);
                    }
                }
                this.LoadAmmoStandingPoint.UserAgent.StopUsingGameObject();
                break;

            case RangedSiegeWeapon.WeaponState.WaitingBeforeIdle:
                this._timeElapsedAfterLoading += dt;
                if ((double)this._timeElapsedAfterLoading <= 1.0)
                {
                    break;
                }
                this.State = RangedSiegeWeapon.WeaponState.Idle;
                break;

            case RangedSiegeWeapon.WeaponState.Reloading:
                using (List <StandingPoint> .Enumerator enumerator = this.ReloadStandingPoints.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        StandingPoint current = enumerator.Current;
                        if (current.HasUser)
                        {
                            ActionIndexCache currentAction = current.UserAgent.GetCurrentAction(1);
                            if (currentAction == this._reload1AnimationActionIndex || currentAction == this._reload2AnimationActionIndex)
                            {
                                current.UserAgent.SetCurrentActionProgress(1, this._body.GameEntity.Skeleton.GetAnimationParameterAtChannel(0));
                            }
                            else if (!GameNetwork.IsClientOrReplay)
                            {
                                ActionIndexCache actionIndexCache = current == this.PilotStandingPoint ? this._reload1AnimationActionIndex : this._reload2AnimationActionIndex;
                                if (!current.UserAgent.SetActionChannel(1, actionIndexCache, startProgress: this._body.GameEntity.Skeleton.GetAnimationParameterAtChannel(0)))
                                {
                                    current.UserAgent.StopUsingGameObject();
                                }
                            }
                        }
                    }
                    break;
                }
            }
        }
Exemple #14
0
 public static void WriteMissileWeaponReferenceToPacket(MissionWeapon weapon)
 {
     GameNetworkMessage.WriteObjectReferenceToPacket((MBObjectBase)weapon.Item, CompressionBasic.GUIDCompressionInfo);
     GameNetworkMessage.WriteIntToPacket(weapon.CurrentUsageIndex, CompressionMission.WeaponUsageIndexCompressionInfo);
 }
Exemple #15
0
        protected internal override void OnTick(float dt)
        {
            base.OnTick(dt);
            if (!GameNetwork.IsClientOrReplay && this._tickOccasionallyTimer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission)))
            {
                this.TickOccasionally();
            }
            if (GameNetwork.IsClientOrReplay)
            {
                return;
            }
            List <StandingPoint> standingPointList = (List <StandingPoint>)null;
            List <Agent>         agentList         = (List <Agent>)null;

            foreach (StandingPoint ammoPickUpPoint in this.AmmoPickUpPoints)
            {
                if (ammoPickUpPoint.HasUser)
                {
                    ActionIndexCache currentAction = ammoPickUpPoint.UserAgent.GetCurrentAction(1);
                    if (!(currentAction == StonePile.act_pickup_boulder_begin))
                    {
                        if (currentAction == StonePile.act_pickup_boulder_end)
                        {
                            MissionWeapon weapon    = new MissionWeapon(this._givenItem, (ItemModifier)null, (Banner)null, (short)1);
                            Agent         userAgent = ammoPickUpPoint.UserAgent;
                            userAgent.EquipWeaponToExtraSlotAndWield(ref weapon);
                            userAgent.StopUsingGameObject();
                            this.ConsumeAmmo();
                            if (userAgent.IsAIControlled)
                            {
                                if (agentList == null)
                                {
                                    agentList = new List <Agent>();
                                }
                                agentList.Add(userAgent);
                            }
                        }
                        else if (!ammoPickUpPoint.UserAgent.SetActionChannel(1, StonePile.act_pickup_boulder_begin))
                        {
                            ammoPickUpPoint.UserAgent.StopUsingGameObject();
                        }
                    }
                }
                if (ammoPickUpPoint.HasAIUser || ammoPickUpPoint.HasAIMovingTo)
                {
                    if (standingPointList == null)
                    {
                        standingPointList = new List <StandingPoint>();
                    }
                    standingPointList.Add(ammoPickUpPoint);
                }
            }
            List <StonePile.ThrowingPoint> throwingPointList = (List <StonePile.ThrowingPoint>)null;

            foreach (StonePile.ThrowingPoint throwingPoint in this._throwingPoints)
            {
                throwingPoint.AmmoPickUpPoint = (StandingPointWithWeaponRequirement)null;
                if ((NativeObject)throwingPoint.AttackEntity != (NativeObject)null || throwingPoint.EnemyInRangeTimer.Check(Mission.Current.Time) && (double)throwingPoint.EnemyInRangeTimer.ElapsedTime() < 3.5)
                {
                    throwingPoint.StandingPoint.IsDeactivated = false;
                    MissionWeapon missionWeapon;
                    if (throwingPoint.StandingPoint.HasAIMovingTo)
                    {
                        Dictionary <Agent, UsableMissionObject.MoveInfo> .Enumerator enumerator = throwingPoint.StandingPoint.MovingAgents.GetEnumerator();
                        enumerator.MoveNext();
                        Agent          key = enumerator.Current.Key;
                        EquipmentIndex wieldedItemIndex = key.GetWieldedItemIndex(Agent.HandIndex.MainHand);
                        if (wieldedItemIndex != EquipmentIndex.None)
                        {
                            missionWeapon = key.Equipment[wieldedItemIndex];
                            if (missionWeapon.Item == this._givenItem)
                            {
                                continue;
                            }
                        }
                        key.StopUsingGameObject();
                    }
                    else if (throwingPoint.StandingPoint.HasUser)
                    {
                        Agent          userAgent        = throwingPoint.StandingPoint.UserAgent;
                        EquipmentIndex wieldedItemIndex = userAgent.GetWieldedItemIndex(Agent.HandIndex.MainHand);
                        if (wieldedItemIndex != EquipmentIndex.None)
                        {
                            missionWeapon = userAgent.Equipment[wieldedItemIndex];
                            if (missionWeapon.Item == this._givenItem)
                            {
                                if (userAgent.Controller == Agent.ControllerType.AI && (NativeObject)throwingPoint.AttackEntity != (NativeObject)null)
                                {
                                    userAgent.DisableScriptedCombatMovement();
                                    userAgent.SetScriptedTargetEntityAndPosition(throwingPoint.AttackEntity, new WorldPosition(throwingPoint.AttackEntity.Scene, UIntPtr.Zero, throwingPoint.AttackEntity.GlobalPosition, false));
                                    continue;
                                }
                                continue;
                            }
                        }
                        userAgent.StopUsingGameObject();
                        if (userAgent.Controller == Agent.ControllerType.AI)
                        {
                            userAgent.DisableScriptedCombatMovement();
                        }
                    }
                    else
                    {
                        if (throwingPointList == null)
                        {
                            throwingPointList = new List <StonePile.ThrowingPoint>();
                        }
                        throwingPointList.Add(throwingPoint);
                    }
                }
                else
                {
                    throwingPoint.StandingPoint.IsDeactivated = true;
                }
            }
            if (standingPointList != null)
            {
                for (int index = 0; index < standingPointList.Count; ++index)
                {
                    if (throwingPointList != null && throwingPointList.Count > index)
                    {
                        throwingPointList[index].AmmoPickUpPoint = standingPointList[index] as StandingPointWithWeaponRequirement;
                    }
                    else
                    {
                        standingPointList[index].UserAgent?.StopUsingGameObject();
                        if (standingPointList[index].HasAIMovingTo)
                        {
                            foreach (KeyValuePair <Agent, UsableMissionObject.MoveInfo> keyValuePair in standingPointList[index].MovingAgents.ToList <KeyValuePair <Agent, UsableMissionObject.MoveInfo> >())
                            {
                                keyValuePair.Key.StopUsingGameObject();
                            }
                            standingPointList[index].MovingAgents.Clear();
                        }
                    }
                }
            }
            if (agentList == null)
            {
                return;
            }
            foreach (Agent agent in agentList)
            {
                this.AssignAgentToStandingPoint(this.GetSuitableStandingPointFor(this.Side, agent, (IEnumerable <Agent>)null, (IEnumerable <AgentValuePair <float> >)null), agent);
            }
        }