Exemple #1
0
        private void CheckMorales()
        {
            if ((double)this._nextTimeToCheckForMorales < 0.0)
            {
                this._nextTimeToCheckForMorales = this.Mission.Time + 1f;
            }
            if ((double)this.Mission.Time < (double)this._nextTimeToCheckForMorales)
            {
                return;
            }
            ++this._nextTimeToCheckForMorales;
            float moraleGain;

            if (!this.GetMoraleGain(out moraleGain))
            {
                return;
            }
            this._morale += moraleGain;
            this._morale  = MBMath.ClampFloat(this._morale, -1f, 1f);
            GameNetwork.BeginBroadcastModuleEvent();
            GameNetwork.WriteMessage((GameNetworkMessage) new FlagDominationMoraleChangeMessage(this.MoraleRounded));
            GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.None);
            this._gameModeFlagDominationClient?.OnMoraleChanged(this.MoraleRounded);
            MPPerkObject.RaiseEventForAllPeers(MPPerkCondition.PerkEventFlags.MoraleChange);
        }
Exemple #2
0
        private void FillAgentStatsFromData(
            ref AgentDrivenProperties agentDrivenProperties,
            MultiplayerClassDivisions.MPHeroClass heroClass,
            MissionPeer missionPeer,
            MissionPeer owningMissionPeer)
        {
            MissionPeer peer = missionPeer ?? owningMissionPeer;

            if (peer != null)
            {
                MPPerkObject.MPOnSpawnPerkHandler spawnPerkHandler = MPPerkObject.GetOnSpawnPerkHandler(peer);
                bool isPlayer = missionPeer != null;
                for (int index = 0; index < 56; ++index)
                {
                    DrivenProperty drivenProperty = (DrivenProperty)index;
                    float          stat           = agentDrivenProperties.GetStat(drivenProperty);
                    if (drivenProperty == DrivenProperty.ArmorHead || drivenProperty == DrivenProperty.ArmorTorso || (drivenProperty == DrivenProperty.ArmorLegs || drivenProperty == DrivenProperty.ArmorArms))
                    {
                        agentDrivenProperties.SetStat(drivenProperty, stat + (float)heroClass.ArmorValue + spawnPerkHandler.GetDrivenPropertyBonusOnSpawn(isPlayer, drivenProperty, stat));
                    }
                    else
                    {
                        agentDrivenProperties.SetStat(drivenProperty, stat + spawnPerkHandler.GetDrivenPropertyBonusOnSpawn(isPlayer, drivenProperty, stat));
                    }
                }
            }
            agentDrivenProperties.TopSpeedReachDuration = heroClass.TopSpeedReachDuration;
            float managedParameter1 = ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.BipedalCombatSpeedMinMultiplier);
            float managedParameter2 = ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.BipedalCombatSpeedMaxMultiplier);

            agentDrivenProperties.CombatMaxSpeedMultiplier = managedParameter1 + (managedParameter2 - managedParameter1) * heroClass.CombatMovementSpeedMultiplier;
        }
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
 protected internal override void OnItemPickup(SpawnedItemEntity item)
 {
     if (item.WeaponCopy.IsEmpty || item.WeaponCopy.Item.ItemType != ItemObject.ItemTypeEnum.Banner)
     {
         return;
     }
     MPPerkObject.GetPerkHandler(this.Agent)?.OnEvent(MPPerkCondition.PerkEventFlags.BannerPickUp);
 }
 public override void OnMissionTick(float dt)
 {
     base.OnMissionTick(dt);
     if ((double)Mission.Current.Time - (double)this._lastPerkTickTime < 1.0)
     {
         return;
     }
     this._lastPerkTickTime = Mission.Current.Time;
     MPPerkObject.TickAllPeerPerks((int)((double)this._lastPerkTickTime / 1.0));
 }
Exemple #6
0
            public override void Deserialize(MBObjectManager objectManager, XmlNode node)
            {
                base.Deserialize(objectManager, node);
                this.HeroCharacter  = MultiplayerClassDivisions.GetMPCharacter(node.Attributes["hero"].Value);
                this.TroopCharacter = MultiplayerClassDivisions.GetMPCharacter(node.Attributes["troop"].Value);
                string stringId = node.Attributes["banner_bearer"]?.Value;

                if (stringId != null)
                {
                    this.BannerBearerCharacter = MultiplayerClassDivisions.GetMPCharacter(stringId);
                }
                this.HeroIdleAnim       = node.Attributes["hero_idle_anim"]?.Value;
                this.HeroMountIdleAnim  = node.Attributes["hero_mount_idle_anim"]?.Value;
                this.TroopIdleAnim      = node.Attributes["troop_idle_anim"]?.Value;
                this.TroopMountIdleAnim = node.Attributes["troop_mount_idle_anim"]?.Value;
                this.Culture            = this.HeroCharacter.Culture;
                this.ClassGroup         = new MultiplayerClassDivisions.MPHeroClassGroup(this.HeroCharacter.DefaultFormationClass.GetName());
                this.TroopMultiplier    = (float)Convert.ToDouble(node.Attributes["multiplier"].Value);
                this.TroopCost          = Convert.ToInt32(node.Attributes["cost"].Value);
                this.ArmorValue         = Convert.ToInt32(node.Attributes["armor"].Value);
                this.Health             = 100;
                this.MeleeAI            = 50;
                this.RangedAI           = 50;
                XmlNode attribute = (XmlNode)node.Attributes["hitpoints"];

                if (attribute != null)
                {
                    this.Health = Convert.ToInt32(attribute.Value);
                }
                this.MovementSpeedMultiplier       = (float)Convert.ToDouble(node.Attributes["movement_speed"].Value);
                this.CombatMovementSpeedMultiplier = (float)Convert.ToDouble(node.Attributes["combat_movement_speed"].Value);
                this.TopSpeedReachDuration         = (float)Convert.ToDouble(node.Attributes["acceleration"].Value);
                this.MeleeAI  = Convert.ToInt32(node.Attributes["melee_ai"].Value);
                this.RangedAI = Convert.ToInt32(node.Attributes["ranged_ai"].Value);
                TargetIconType result;

                if (Enum.TryParse <TargetIconType>(node.Attributes["icon"].Value, true, out result))
                {
                    this.IconType = result;
                }
                foreach (XmlNode childNode1 in node.ChildNodes)
                {
                    if (childNode1.NodeType != XmlNodeType.Comment && childNode1.Name == "Perks")
                    {
                        this._perks = new List <IReadOnlyPerkObject>();
                        foreach (XmlNode childNode2 in childNode1.ChildNodes)
                        {
                            if (childNode2.NodeType != XmlNodeType.Comment)
                            {
                                this._perks.Add(MPPerkObject.Deserialize(childNode2));
                            }
                        }
                    }
                }
            }
Exemple #7
0
 private void OnMountHealthChanged(Agent agent, float oldHealth, float newHealth)
 {
     if (this.Agent.IsActive() && this.Agent.MountAgent == agent)
     {
         MPPerkObject.GetPerkHandler(this.Agent)?.OnEvent(this.Agent, MPPerkCondition.PerkEventFlags.MountHealthChange);
     }
     else
     {
         agent.OnAgentHealthChanged -= new Agent.OnAgentHealthChangedDelegate(this.OnMountHealthChanged);
     }
 }
Exemple #8
0
        private void UpdateMountAgentStats(Agent agent, AgentDrivenProperties agentDrivenProperties)
        {
            MPPerkObject.MPPerkHandler perkHandler      = MPPerkObject.GetPerkHandler(agent.RiderAgent);
            EquipmentElement           mountElement     = agent.SpawnEquipment[EquipmentIndex.ArmorItemEndSlot];
            EquipmentElement           equipmentElement = agent.SpawnEquipment[EquipmentIndex.HorseHarness];

            agentDrivenProperties.MountManeuver = (float)mountElement.GetModifiedMountManeuver(in equipmentElement) * (float)(1.0 + (perkHandler != null ? (double)perkHandler.GetMountManeuver() : 0.0));
            agentDrivenProperties.MountSpeed    = (float)((double)(mountElement.GetModifiedMountSpeed(in equipmentElement) + 1) * 0.219999998807907 * (1.0 + (perkHandler != null ? (double)perkHandler.GetMountSpeed() : 0.0)));
            Agent riderAgent  = agent.RiderAgent;
            int   ridingSkill = riderAgent != null?riderAgent.Character.GetSkillValue(DefaultSkills.Riding) : 0;

            agentDrivenProperties.TopSpeedReachDuration = Game.Current.BasicModels.RidingModel.CalculateAcceleration(in mountElement, in equipmentElement, ridingSkill);
            if (agent.RiderAgent == null)
            {
                return;
            }
            agentDrivenProperties.MountSpeed    *= (float)(1.0 + (double)ridingSkill * (2.0 / 625.0));
            agentDrivenProperties.MountManeuver *= (float)(1.0 + (double)ridingSkill * 0.00350000010803342);
        }
Exemple #9
0
 protected internal override void OnDismount(Agent mount)
 {
     mount.OnAgentHealthChanged -= new Agent.OnAgentHealthChangedDelegate(this.OnMountHealthChanged);
     mount.UpdateAgentProperties();
     MPPerkObject.GetPerkHandler(this.Agent)?.OnEvent(this.Agent, MPPerkCondition.PerkEventFlags.MountChange);
 }
Exemple #10
0
        private void UpdateHumanAgentStats(Agent agent, AgentDrivenProperties agentDrivenProperties)
        {
            MPPerkObject.MPPerkHandler perkHandler = MPPerkObject.GetPerkHandler(agent);
            BasicCharacterObject       character   = agent.Character;
            MissionEquipment           equipment   = agent.Equipment;
            float          num1 = equipment.GetTotalWeightOfWeapons() * (float)(1.0 + (perkHandler != null ? (double)perkHandler.GetEncumbrance(true) : 0.0));
            EquipmentIndex wieldedItemIndex1 = agent.GetWieldedItemIndex(Agent.HandIndex.MainHand);
            EquipmentIndex wieldedItemIndex2 = agent.GetWieldedItemIndex(Agent.HandIndex.OffHand);

            if (wieldedItemIndex1 != EquipmentIndex.None)
            {
                ItemObject      itemObject       = equipment[wieldedItemIndex1].Item;
                WeaponComponent weaponComponent  = itemObject.WeaponComponent;
                float           realWeaponLength = weaponComponent.PrimaryWeapon.GetRealWeaponLength();
                float           num2             = (weaponComponent.GetItemType() == ItemObject.ItemTypeEnum.Bow ? 4f : 1.5f) * itemObject.Weight * MathF.Sqrt(realWeaponLength) * (float)(1.0 + (perkHandler != null ? (double)perkHandler.GetEncumbrance(false) : 0.0));
                num1 += num2;
            }
            if (wieldedItemIndex2 != EquipmentIndex.None)
            {
                float num2 = 1.5f * equipment[wieldedItemIndex2].Item.Weight * (float)(1.0 + (perkHandler != null ? (double)perkHandler.GetEncumbrance(false) : 0.0));
                num1 += num2;
            }
            agentDrivenProperties.WeaponsEncumbrance = num1;
            EquipmentIndex      wieldedItemIndex3   = agent.GetWieldedItemIndex(Agent.HandIndex.MainHand);
            WeaponComponentData weaponComponentData = wieldedItemIndex3 != EquipmentIndex.None ? equipment[wieldedItemIndex3].CurrentUsageItem : (WeaponComponentData)null;
            ItemObject          primaryItem         = wieldedItemIndex3 != EquipmentIndex.None ? equipment[wieldedItemIndex3].Item : (ItemObject)null;
            EquipmentIndex      wieldedItemIndex4   = agent.GetWieldedItemIndex(Agent.HandIndex.OffHand);
            WeaponComponentData secondaryItem       = wieldedItemIndex4 != EquipmentIndex.None ? equipment[wieldedItemIndex4].CurrentUsageItem : (WeaponComponentData)null;
            float inaccuracy;

            agentDrivenProperties.LongestRangedWeaponSlotIndex       = (float)equipment.GetLongestRangedWeaponWithAimingError(out inaccuracy, agent);
            agentDrivenProperties.LongestRangedWeaponInaccuracy      = inaccuracy;
            agentDrivenProperties.SwingSpeedMultiplier               = (float)(0.930000007152557 + 0.000699999975040555 * (double)this.GetSkillValueForItem(character, primaryItem));
            agentDrivenProperties.ThrustOrRangedReadySpeedMultiplier = agentDrivenProperties.SwingSpeedMultiplier;
            agentDrivenProperties.HandlingMultiplier = 1f;
            agentDrivenProperties.ShieldBashStunDurationMultiplier = 1f;
            agentDrivenProperties.KickStunDurationMultiplier       = 1f;
            agentDrivenProperties.ReloadSpeed = (float)(0.930000007152557 + 0.000699999975040555 * (double)this.GetSkillValueForItem(character, primaryItem));
            agentDrivenProperties.ReloadMovementPenaltyFactor = 1f;
            agentDrivenProperties.WeaponInaccuracy            = 0.0f;
            MultiplayerClassDivisions.MPHeroClass classForCharacter = MultiplayerClassDivisions.GetMPHeroClassForCharacter(agent.Character);
            agentDrivenProperties.MaxSpeedMultiplier = (float)(1.04999995231628 * ((double)classForCharacter.MovementSpeedMultiplier * (100.0 / (100.0 + (double)num1))));
            int  skillValue = character.GetSkillValue(DefaultSkills.Riding);
            bool flag1      = false;
            bool flag2      = false;

            if (weaponComponentData != null)
            {
                int weaponSkill = character.GetSkillValue(weaponComponentData.RelevantSkill);
                if (weaponSkill > 0 && weaponComponentData.IsRangedWeapon && perkHandler != null)
                {
                    weaponSkill = MathF.Ceiling((float)weaponSkill * (perkHandler.GetRangedAccuracy() + 1f));
                }
                int thrustSpeed = weaponComponentData.ThrustSpeed;
                agentDrivenProperties.WeaponInaccuracy = this.GetWeaponInaccuracy(agent, weaponComponentData, weaponSkill);
                if (weaponComponentData.IsRangedWeapon)
                {
                    agentDrivenProperties.WeaponMaxMovementAccuracyPenalty = (float)(500 - weaponSkill) * 0.00025f;
                    agentDrivenProperties.WeaponMaxUnsteadyAccuracyPenalty = (float)(500 - weaponSkill) * 0.0002f;
                    if (agent.HasMount)
                    {
                        agentDrivenProperties.WeaponMaxUnsteadyAccuracyPenalty *= Math.Max(1f, (float)(700 - weaponSkill - skillValue) * (3f / 1000f));
                        agentDrivenProperties.WeaponMaxMovementAccuracyPenalty *= Math.Max(1f, (float)(700 - weaponSkill - skillValue) * 0.0033f);
                    }
                    else if (weaponComponentData.RelevantSkill == DefaultSkills.Bow)
                    {
                        agentDrivenProperties.WeaponMaxUnsteadyAccuracyPenalty *= 4.5f / MBMath.Lerp(0.75f, 2f, (float)(((double)thrustSpeed - 60.0) / 75.0));
                        agentDrivenProperties.WeaponMaxMovementAccuracyPenalty *= 6f;
                    }
                    else if (weaponComponentData.RelevantSkill == DefaultSkills.Crossbow)
                    {
                        agentDrivenProperties.WeaponMaxUnsteadyAccuracyPenalty *= 1.2f;
                        agentDrivenProperties.WeaponMaxMovementAccuracyPenalty *= 2.5f;
                    }
                    else if (weaponComponentData.RelevantSkill == DefaultSkills.Throwing)
                    {
                        agentDrivenProperties.WeaponMaxUnsteadyAccuracyPenalty *= 3.5f * MBMath.Lerp(1.5f, 0.8f, (float)(((double)thrustSpeed - 89.0) / 13.0));
                    }
                    if (weaponComponentData.WeaponClass == WeaponClass.Bow)
                    {
                        flag1 = true;
                        agentDrivenProperties.WeaponBestAccuracyWaitTime = (float)(0.300000011920929 + (95.75 - (double)thrustSpeed) * 0.00499999988824129);
                        agentDrivenProperties.WeaponUnsteadyBeginTime    = (float)(0.100000001490116 + (double)weaponSkill * 0.00999999977648258 * (double)MBMath.Lerp(1f, 2f, (float)(((double)thrustSpeed - 60.0) / 75.0)));
                        if (agent.IsAIControlled)
                        {
                            agentDrivenProperties.WeaponUnsteadyBeginTime *= 4f;
                        }
                        agentDrivenProperties.WeaponUnsteadyEndTime = 2f + agentDrivenProperties.WeaponUnsteadyBeginTime;
                        agentDrivenProperties.WeaponRotationalAccuracyPenaltyInRadians = 0.1f;
                    }
                    else if (weaponComponentData.WeaponClass == WeaponClass.Javelin || weaponComponentData.WeaponClass == WeaponClass.ThrowingAxe || weaponComponentData.WeaponClass == WeaponClass.ThrowingKnife)
                    {
                        agentDrivenProperties.WeaponBestAccuracyWaitTime = (float)(0.400000005960464 + (89.0 - (double)thrustSpeed) * 0.0299999993294477);
                        agentDrivenProperties.WeaponUnsteadyBeginTime    = (float)(2.5 + (double)weaponSkill * 0.00999999977648258);
                        agentDrivenProperties.WeaponUnsteadyEndTime      = 10f + agentDrivenProperties.WeaponUnsteadyBeginTime;
                        agentDrivenProperties.WeaponRotationalAccuracyPenaltyInRadians = 0.025f;
                    }
                    else
                    {
                        agentDrivenProperties.WeaponBestAccuracyWaitTime = 0.1f;
                        agentDrivenProperties.WeaponUnsteadyBeginTime    = 0.0f;
                        agentDrivenProperties.WeaponUnsteadyEndTime      = 0.0f;
                        agentDrivenProperties.WeaponRotationalAccuracyPenaltyInRadians = 0.1f;
                    }
                }
                else if (weaponComponentData.WeaponFlags.HasAllFlags <WeaponFlags>(WeaponFlags.WideGrip))
                {
                    flag2 = true;
                    agentDrivenProperties.WeaponUnsteadyBeginTime = (float)(1.0 + (double)weaponSkill * 0.00499999988824129);
                    agentDrivenProperties.WeaponUnsteadyEndTime   = (float)(3.0 + (double)weaponSkill * 0.00999999977648258);
                }
            }
            agentDrivenProperties.AttributeShieldMissileCollisionBodySizeAdder = 0.3f;
            Agent mountAgent = agent.MountAgent;
            float num3       = mountAgent != null?mountAgent.GetAgentDrivenPropertyValue(DrivenProperty.AttributeRiding) : 1f;

            agentDrivenProperties.AttributeRiding                    = (float)skillValue * num3;
            agentDrivenProperties.AttributeHorseArchery              = Game.Current.BasicModels.StrikeMagnitudeModel.CalculateHorseArcheryFactor(character);
            agentDrivenProperties.BipedalRangedReadySpeedMultiplier  = ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.BipedalRangedReadySpeedMultiplier);
            agentDrivenProperties.BipedalRangedReloadSpeedMultiplier = ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.BipedalRangedReloadSpeedMultiplier);
            foreach (DrivenPropertyBonusAgentComponent bonusAgentComponent in agent.Components.OfType <DrivenPropertyBonusAgentComponent>())
            {
                if (!MBMath.IsBetween((int)bonusAgentComponent.DrivenProperty, 0, 56))
                {
                    float num2 = agentDrivenProperties.GetStat(bonusAgentComponent.DrivenProperty) + bonusAgentComponent.DrivenPropertyBonus;
                    agentDrivenProperties.SetStat(bonusAgentComponent.DrivenProperty, num2);
                }
            }
            if (perkHandler != null)
            {
                for (int index = 56; index < 85; ++index)
                {
                    DrivenProperty drivenProperty = (DrivenProperty)index;
                    if (((drivenProperty == DrivenProperty.WeaponUnsteadyBeginTime ? 0 : (drivenProperty != DrivenProperty.WeaponUnsteadyEndTime ? 1 : 0)) | (flag1 ? 1 : 0) | (flag2 ? 1 : 0)) != 0 && drivenProperty != DrivenProperty.WeaponRotationalAccuracyPenaltyInRadians | flag1)
                    {
                        float stat = agentDrivenProperties.GetStat(drivenProperty);
                        agentDrivenProperties.SetStat(drivenProperty, stat + perkHandler.GetDrivenPropertyBonus(drivenProperty, stat));
                    }
                }
            }
            this.SetAiRelatedProperties(agent, agentDrivenProperties, weaponComponentData, secondaryItem);
        }
        protected override void SpawnAgents()
        {
            BasicCultureObject cultureLimit1 = MBObjectManager.Instance.GetObject <BasicCultureObject>(MultiplayerOptions.OptionType.CultureTeam1.GetStrValue());
            BasicCultureObject cultureLimit2 = MBObjectManager.Instance.GetObject <BasicCultureObject>(MultiplayerOptions.OptionType.CultureTeam2.GetStrValue());

            foreach (MissionPeer peer in VirtualPlayer.Peers <MissionPeer>())
            {
                NetworkCommunicator networkPeer = peer.GetNetworkPeer();
                if (networkPeer.IsSynchronized && peer.ControlledAgent == null && (!peer.HasSpawnedAgentVisuals && peer.Team != null) && (peer.Team != this.Mission.SpectatorTeam && peer.SpawnTimer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission))))
                {
                    BasicCultureObject basicCultureObject = peer.Team.Side == BattleSideEnum.Attacker ? cultureLimit1 : cultureLimit2;
                    MultiplayerClassDivisions.MPHeroClass heroClassForPeer = MultiplayerClassDivisions.GetMPHeroClassForPeer(peer);
                    if (heroClassForPeer == null || heroClassForPeer.TroopCost > this.GameMode.GetCurrentGoldForPeer(peer))
                    {
                        if (peer.SelectedTroopIndex != 0)
                        {
                            peer.SelectedTroopIndex = 0;
                            GameNetwork.BeginBroadcastModuleEvent();
                            GameNetwork.WriteMessage((GameNetworkMessage) new UpdateSelectedTroopIndex(networkPeer, 0));
                            GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.ExcludeOtherTeamPlayers, networkPeer);
                        }
                    }
                    else
                    {
                        BasicCharacterObject heroCharacter = heroClassForPeer.HeroCharacter;
                        Equipment            equipment     = heroCharacter.Equipment.Clone();
                        IEnumerable <(EquipmentIndex, EquipmentElement)> alternativeEquipments = MPPerkObject.GetOnSpawnPerkHandler(peer)?.GetAlternativeEquipments(true);
                        if (alternativeEquipments != null)
                        {
                            foreach ((EquipmentIndex, EquipmentElement)tuple in alternativeEquipments)
                            {
                                equipment[tuple.Item1] = tuple.Item2;
                            }
                        }
                        AgentBuildData agentBuildData = new AgentBuildData(heroCharacter);
                        agentBuildData.MissionPeer(peer);
                        agentBuildData.Equipment(equipment);
                        agentBuildData.Team(peer.Team);
                        agentBuildData.IsFemale(peer.Peer.IsFemale);
                        agentBuildData.BodyProperties(this.GetBodyProperties(peer, peer.Team == this.Mission.AttackerTeam ? cultureLimit1 : cultureLimit2));
                        agentBuildData.VisualsIndex(0);
                        agentBuildData.ClothingColor1(peer.Team == this.Mission.AttackerTeam ? basicCultureObject.Color : basicCultureObject.ClothAlternativeColor);
                        agentBuildData.ClothingColor2(peer.Team == this.Mission.AttackerTeam ? basicCultureObject.Color2 : basicCultureObject.ClothAlternativeColor2);
                        agentBuildData.TroopOrigin((IAgentOriginBase) new BasicBattleAgentOrigin(heroCharacter));
                        if (this.GameMode.ShouldSpawnVisualsForServer(networkPeer))
                        {
                            this.AgentVisualSpawnComponent.SpawnAgentVisualsForPeer(peer, agentBuildData, peer.SelectedTroopIndex);
                        }
                        this.GameMode.HandleAgentVisualSpawning(networkPeer, agentBuildData);
                    }
                }
            }
            if (this.Mission.AttackerTeam != null)
            {
                int num = 0;
                foreach (Agent activeAgent in this.Mission.AttackerTeam.ActiveAgents)
                {
                    if (activeAgent.Character != null && activeAgent.MissionPeer == null)
                    {
                        ++num;
                    }
                }
                if (num < MultiplayerOptions.OptionType.NumberOfBotsTeam1.GetIntValue())
                {
                    this.SpawnBot(this.Mission.AttackerTeam, cultureLimit1);
                }
            }
            if (this.Mission.DefenderTeam == null)
            {
                return;
            }
            int num1 = 0;

            foreach (Agent activeAgent in this.Mission.DefenderTeam.ActiveAgents)
            {
                if (activeAgent.Character != null && activeAgent.MissionPeer == null)
                {
                    ++num1;
                }
            }
            if (num1 >= MultiplayerOptions.OptionType.NumberOfBotsTeam2.GetIntValue())
            {
                return;
            }
            this.SpawnBot(this.Mission.DefenderTeam, cultureLimit2);
        }
Exemple #12
0
 public override void OnAgentRemoved(
     Agent affectedAgent,
     Agent affectorAgent,
     AgentState agentState,
     KillingBlow blow)
 {
     base.OnAgentRemoved(affectedAgent, affectorAgent, agentState, blow);
     if (this.UseGold() && affectorAgent != null && (affectedAgent != null && affectedAgent.IsHuman) && (blow.DamageType != DamageTypes.Invalid && (agentState == AgentState.Unconscious || agentState == AgentState.Killed)))
     {
         Agent.Hitter assistingHitter = affectedAgent.GetAssistingHitter(affectorAgent.MissionPeer);
         MultiplayerClassDivisions.MPHeroClass classForCharacter = MultiplayerClassDivisions.GetMPHeroClassForCharacter(affectedAgent.Character);
         if (affectorAgent.MissionPeer != null && affectorAgent.MissionPeer.Representative is FlagDominationMissionRepresentative representative10)
         {
             int gainsFromKillData = representative10.GetGoldGainsFromKillData(MPPerkObject.GetPerkHandler(affectorAgent.MissionPeer), MPPerkObject.GetPerkHandler(assistingHitter?.HitterPeer), classForCharacter, false);
             if (gainsFromKillData > 0)
             {
                 this.ChangeCurrentGoldForPeer(affectorAgent.MissionPeer, representative10.Gold + gainsFromKillData);
             }
         }
         if (assistingHitter?.HitterPeer != null && !assistingHitter.IsFriendlyHit && assistingHitter.HitterPeer.Representative is FlagDominationMissionRepresentative representative11)
         {
             int gainsFromKillData = representative11.GetGoldGainsFromKillData(MPPerkObject.GetPerkHandler(affectorAgent.MissionPeer), MPPerkObject.GetPerkHandler(assistingHitter.HitterPeer), classForCharacter, false);
             if (gainsFromKillData > 0)
             {
                 this.ChangeCurrentGoldForPeer(assistingHitter.HitterPeer, representative11.Gold + gainsFromKillData);
             }
         }
         if (affectedAgent.MissionPeer?.Team != null)
         {
             IEnumerable <(MissionPeer, int)> goldRewardsOnDeath = MPPerkObject.GetPerkHandler(affectedAgent.MissionPeer)?.GetTeamGoldRewardsOnDeath();
             if (goldRewardsOnDeath != null)
             {
                 foreach ((MissionPeer peer6, int baseAmount6) in goldRewardsOnDeath)
                 {
                     if (baseAmount6 > 0 && peer6?.Representative is FlagDominationMissionRepresentative representative12)
                     {
                         int local_11 = representative12.GetGoldGainsFromAllyDeathReward(baseAmount6);
                         if (local_11 > 0)
                         {
                             this.ChangeCurrentGoldForPeer(peer6, representative12.Gold + local_11);
                         }
                     }
                 }
             }
         }
     }
     if (affectedAgent.IsPlayerControlled)
     {
         affectedAgent.MissionPeer.GetComponent <FlagDominationMissionRepresentative>().UpdateSelectedClassServer((Agent)null);
     }
     else
     {
         if (MultiplayerOptions.OptionType.NumberOfBotsPerFormation.GetIntValue() <= 0 || this.WarmupComponent != null && this.WarmupComponent.IsInWarmup || (affectedAgent.IsMount || affectedAgent.OwningAgentMissionPeer == null || (affectedAgent.Formation == null || affectedAgent.Formation.CountOfUnits != 1)))
         {
             return;
         }
         if (!GameNetwork.IsDedicatedServer)
         {
             MatrixFrame cameraFrame = Mission.Current.GetCameraFrame();
             Vec3        position    = cameraFrame.origin + cameraFrame.rotation.u;
             MBSoundEvent.PlaySound(SoundEvent.GetEventIdFromString("event:/alerts/report/squad_wiped"), position);
         }
         GameNetwork.BeginBroadcastModuleEvent();
         GameNetwork.WriteMessage((GameNetworkMessage) new FormationWipedMessage());
         GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.ExcludeOtherTeamPlayers, affectedAgent.OwningAgentMissionPeer.GetNetworkPeer());
     }
 }
Exemple #13
0
 private void TickFlags(float dt)
 {
     this._dtSumFlagStateCheck += dt;
     if ((double)this._dtSumFlagStateCheck < 0.25)
     {
         return;
     }
     this._dtSumFlagStateCheck -= 0.25f;
     foreach (FlagCapturePoint allCapturePoint in this.AllCapturePoints)
     {
         if (!allCapturePoint.IsDeactivated)
         {
             Team  capturePointOwner = this._capturePointOwners[allCapturePoint.FlagIndex];
             Agent agent1            = (Agent)null;
             float num1 = float.MaxValue;
             foreach (Agent agent2 in Mission.Current.GetAgentsInRange(allCapturePoint.Position.AsVec2, 4f).Where <Agent>((Func <Agent, bool>)(a => a.IsHuman && a.IsActive())))
             {
                 float num2 = agent2.Position.DistanceSquared(allCapturePoint.Position);
                 if ((double)num2 <= 16.0 && (double)num2 < (double)num1)
                 {
                     agent1 = agent2;
                     num1   = num2;
                 }
             }
             bool isContested = allCapturePoint.IsContested;
             if (capturePointOwner == null)
             {
                 if (!isContested && agent1 != null)
                 {
                     allCapturePoint.SetMoveFlag(CaptureTheFlagFlagDirection.Down);
                 }
                 else if (agent1 == null & isContested)
                 {
                     allCapturePoint.SetMoveFlag(CaptureTheFlagFlagDirection.Up);
                 }
             }
             else if (agent1 != null)
             {
                 if (agent1.Team != capturePointOwner && !isContested)
                 {
                     allCapturePoint.SetMoveFlag(CaptureTheFlagFlagDirection.Down);
                 }
                 else if (agent1.Team == capturePointOwner & isContested)
                 {
                     allCapturePoint.SetMoveFlag(CaptureTheFlagFlagDirection.Up);
                 }
             }
             else if (isContested)
             {
                 allCapturePoint.SetMoveFlag(CaptureTheFlagFlagDirection.Up);
             }
             bool ownerTeamChanged;
             allCapturePoint.OnAfterTick(agent1 != null, out ownerTeamChanged);
             if (ownerTeamChanged)
             {
                 Team team   = agent1.Team;
                 uint color  = team != null ? team.Color : 4284111450U;
                 uint color2 = team != null ? team.Color2 : uint.MaxValue;
                 allCapturePoint.SetTeamColorsWithAllSynched(color, color2);
                 this._capturePointOwners[allCapturePoint.FlagIndex] = team;
                 GameNetwork.BeginBroadcastModuleEvent();
                 GameNetwork.WriteMessage((GameNetworkMessage) new FlagDominationCapturePointMessage(allCapturePoint.FlagIndex, team));
                 GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.None);
                 this._gameModeFlagDominationClient?.OnCapturePointOwnerChanged(allCapturePoint, team);
                 this.NotificationsComponent.FlagXCapturedByTeamX((SynchedMissionObject)allCapturePoint, agent1.Team);
                 MPPerkObject.RaiseEventForAllPeers(MPPerkCondition.PerkEventFlags.FlagCapture);
             }
         }
     }
 }
Exemple #14
0
        private void CheckRemovingOfPoints()
        {
            if ((double)this._nextTimeToCheckForPointRemoval < 0.0)
            {
                this._nextTimeToCheckForPointRemoval = this.Mission.Time + this._pointRemovalTimeInSeconds;
            }
            if ((double)this.Mission.Time < (double)this._nextTimeToCheckForPointRemoval)
            {
                return;
            }
            this._nextTimeToCheckForPointRemoval += this._pointRemovalTimeInSeconds;
            List <BattleSideEnum> battleSideEnumList = new List <BattleSideEnum>();

            foreach (Team team1 in (ReadOnlyCollection <Team>) this.Mission.Teams)
            {
                Team team = team1;
                if (team.Side != BattleSideEnum.None)
                {
                    int num = (int)team.Side * 2 - 1;
                    if (this.AllCapturePoints.All <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(cp => this.GetFlagOwnerTeam(cp) != team)))
                    {
                        if (this.AllCapturePoints.FirstOrDefault <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(cp => this.GetFlagOwnerTeam(cp) == null)) != null)
                        {
                            this._morale -= 0.1f * (float)num;
                            battleSideEnumList.Add(BattleSideEnum.None);
                        }
                        else
                        {
                            this._morale -= (float)(0.100000001490116 * (double)num * 2.0);
                            battleSideEnumList.Add(team.Side.GetOppositeSide());
                        }
                        this._morale = MBMath.ClampFloat(this._morale, -1f, 1f);
                    }
                    else
                    {
                        battleSideEnumList.Add(team.Side);
                    }
                }
            }
            List <int> removedCapIndexList = new List <int>();
            List <FlagCapturePoint> list1  = this.AllCapturePoints.ToList <FlagCapturePoint>();

            foreach (BattleSideEnum battleSideEnum in battleSideEnumList)
            {
                BattleSideEnum side = battleSideEnum;
                if (side == BattleSideEnum.None)
                {
                    removedCapIndexList.Add(this.RemoveCapturePoint(list1.GetRandomElementWithPredicate <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(cp => this.GetFlagOwnerTeam(cp) == null))));
                }
                else
                {
                    List <FlagCapturePoint> list2 = list1.Where <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(cp => this.GetFlagOwnerTeam(cp) != null && this.GetFlagOwnerTeam(cp).Side == side)).ToList <FlagCapturePoint>();
                    List <FlagCapturePoint> list3 = list2.Where <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(cp => this.GetNumberOfAttackersAroundFlag(cp) == 0)).ToList <FlagCapturePoint>();
                    if (list3.Any <FlagCapturePoint>())
                    {
                        removedCapIndexList.Add(this.RemoveCapturePoint(list3.GetRandomElement <FlagCapturePoint>()));
                    }
                    else
                    {
                        List <KeyValuePair <FlagCapturePoint, int> > keyValuePairList = new List <KeyValuePair <FlagCapturePoint, int> >();
                        foreach (FlagCapturePoint flagCapturePoint in list2)
                        {
                            if (!keyValuePairList.Any <KeyValuePair <FlagCapturePoint, int> >())
                            {
                                keyValuePairList.Add(new KeyValuePair <FlagCapturePoint, int>(flagCapturePoint, this.GetNumberOfAttackersAroundFlag(flagCapturePoint)));
                            }
                            else
                            {
                                int count = this.GetNumberOfAttackersAroundFlag(flagCapturePoint);
                                if (keyValuePairList.Any <KeyValuePair <FlagCapturePoint, int> >((Func <KeyValuePair <FlagCapturePoint, int>, bool>)(cc => cc.Value > count)))
                                {
                                    keyValuePairList.Clear();
                                    keyValuePairList.Add(new KeyValuePair <FlagCapturePoint, int>(flagCapturePoint, count));
                                }
                                else if (keyValuePairList.Any <KeyValuePair <FlagCapturePoint, int> >((Func <KeyValuePair <FlagCapturePoint, int>, bool>)(cc => cc.Value == count)))
                                {
                                    keyValuePairList.Add(new KeyValuePair <FlagCapturePoint, int>(flagCapturePoint, count));
                                }
                            }
                        }
                        removedCapIndexList.Add(this.RemoveCapturePoint(keyValuePairList.GetRandomElement <KeyValuePair <FlagCapturePoint, int> >().Key));
                    }
                }
                FlagCapturePoint flagCapturePoint1 = list1.First <FlagCapturePoint>(closure_0 ?? (closure_0 = (Func <FlagCapturePoint, bool>)(fl => fl.FlagIndex == removedCapIndexList[removedCapIndexList.Count - 1])));
                list1.Remove(flagCapturePoint1);
            }
            removedCapIndexList.Sort();
            int first  = removedCapIndexList[0];
            int second = removedCapIndexList[1];
            FlagCapturePoint remainingFlag = this.AllCapturePoints.First <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(cp => cp.FlagIndex != first && cp.FlagIndex != second));

            this.NotificationsComponent.FlagXRemaining(remainingFlag);
            GameNetwork.BeginBroadcastModuleEvent();
            GameNetwork.WriteMessage((GameNetworkMessage) new FlagDominationMoraleChangeMessage(this.MoraleRounded));
            GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.None);
            GameNetwork.BeginBroadcastModuleEvent();
            GameNetwork.WriteMessage((GameNetworkMessage) new FlagDominationFlagsRemovedMessage());
            GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.None);
            this._flagRemovalOccured = true;
            this._gameModeFlagDominationClient?.OnNumberOfFlagsChanged();
            foreach (MissionBehaviour missionBehaviour in this.Mission.MissionBehaviours)
            {
                if (missionBehaviour is IFlagRemoved flagRemoved1)
                {
                    flagRemoved1.OnFlagsRemoved(remainingFlag.FlagIndex);
                }
            }
            MPPerkObject.RaiseEventForAllPeers(MPPerkCondition.PerkEventFlags.FlagRemoval);
        }
        public virtual void OnTick(float dt)
        {
            foreach (MissionPeer peer in VirtualPlayer.Peers <MissionPeer>())
            {
                if (peer.GetNetworkPeer().IsSynchronized&& peer.ControlledAgent == null && (peer.HasSpawnedAgentVisuals && !this.CanUpdateSpawnEquipment(peer)))
                {
                    BasicCultureObject basicCultureObject1 = MBObjectManager.Instance.GetObject <BasicCultureObject>(MultiplayerOptions.OptionType.CultureTeam1.GetStrValue());
                    BasicCultureObject basicCultureObject2 = MBObjectManager.Instance.GetObject <BasicCultureObject>(MultiplayerOptions.OptionType.CultureTeam2.GetStrValue());
                    MultiplayerClassDivisions.MPHeroClass heroClassForPeer = MultiplayerClassDivisions.GetMPHeroClassForPeer(peer);
                    MPPerkObject.MPOnSpawnPerkHandler     spawnPerkHandler = MPPerkObject.GetOnSpawnPerkHandler(peer);
                    int  num1  = 0;
                    bool flag1 = false;
                    if (MultiplayerOptions.OptionType.NumberOfBotsPerFormation.GetIntValue() > 0 && (this.GameMode.WarmupComponent == null || !this.GameMode.WarmupComponent.IsInWarmup))
                    {
                        num1 = MPPerkObject.GetTroopCount(heroClassForPeer, spawnPerkHandler);
                        foreach (MPPerkObject selectedPerk in (IEnumerable <MPPerkObject>)peer.SelectedPerks)
                        {
                            if (selectedPerk.HasBannerBearer)
                            {
                                flag1 = true;
                                break;
                            }
                        }
                    }
                    if (num1 > 0)
                    {
                        num1 = (int)((double)num1 * (double)this.GameMode.GetTroopNumberMultiplierForMissingPlayer(peer));
                    }
                    int num2 = num1 + (flag1 ? 2 : 1);
                    IEnumerable <(EquipmentIndex, EquipmentElement)> alternativeEquipments = spawnPerkHandler?.GetAlternativeEquipments(false);
                    for (int index = 0; index < num2; ++index)
                    {
                        bool isPlayer = index == 0;
                        BasicCharacterObject basicCharacterObject = isPlayer ? heroClassForPeer.HeroCharacter : (!flag1 || index != 1 ? heroClassForPeer.TroopCharacter : heroClassForPeer.BannerBearerCharacter);
                        AgentBuildData       agentBuildData       = new AgentBuildData(basicCharacterObject);
                        if (isPlayer)
                        {
                            agentBuildData.MissionPeer(peer);
                        }
                        else
                        {
                            agentBuildData.OwningMissionPeer(peer);
                        }
                        agentBuildData.VisualsIndex(index);
                        Equipment equipment = isPlayer ? basicCharacterObject.Equipment.Clone() : Equipment.GetRandomEquipmentElements(basicCharacterObject, false, seed: MBRandom.RandomInt());
                        IEnumerable <(EquipmentIndex, EquipmentElement)> valueTuples = isPlayer ? spawnPerkHandler?.GetAlternativeEquipments(true) : alternativeEquipments;
                        if (valueTuples != null)
                        {
                            foreach ((EquipmentIndex, EquipmentElement)valueTuple in valueTuples)
                            {
                                equipment[valueTuple.Item1] = valueTuple.Item2;
                            }
                        }
                        agentBuildData.Equipment(equipment);
                        agentBuildData.Team(peer.Team);
                        agentBuildData.Formation(peer.ControlledFormation);
                        agentBuildData.IsFemale(isPlayer ? peer.Peer.IsFemale : basicCharacterObject.IsFemale);
                        agentBuildData.TroopOrigin((IAgentOriginBase) new BasicBattleAgentOrigin(basicCharacterObject));
                        BasicCultureObject basicCultureObject3 = peer.Team == this.Mission.AttackerTeam ? basicCultureObject1 : basicCultureObject2;
                        if (isPlayer)
                        {
                            agentBuildData.BodyProperties(this.GetBodyProperties(peer, peer.Team == this.Mission.AttackerTeam ? basicCultureObject1 : basicCultureObject2));
                        }
                        else
                        {
                            agentBuildData.EquipmentSeed(this.MissionLobbyComponent.GetRandomFaceSeedForCharacter(basicCharacterObject, agentBuildData.AgentVisualsIndex));
                            agentBuildData.BodyProperties(BodyProperties.GetRandomBodyProperties(agentBuildData.AgentIsFemale, basicCharacterObject.GetBodyPropertiesMin(), basicCharacterObject.GetBodyPropertiesMax(), (int)agentBuildData.AgentOverridenSpawnEquipment.HairCoverType, agentBuildData.AgentEquipmentSeed, basicCharacterObject.HairTags, basicCharacterObject.BeardTags, basicCharacterObject.TattooTags));
                        }
                        agentBuildData.ClothingColor1(peer.Team == this.Mission.AttackerTeam ? basicCultureObject3.Color : basicCultureObject3.ClothAlternativeColor);
                        agentBuildData.ClothingColor2(peer.Team == this.Mission.AttackerTeam ? basicCultureObject3.Color2 : basicCultureObject3.ClothAlternativeColor2);
                        Banner banner = new Banner(peer.Peer.BannerCode, peer.Team.Color, peer.Team.Color2);
                        agentBuildData.Banner(banner);
                        if (peer.ControlledFormation != null && peer.ControlledFormation.Banner == null)
                        {
                            peer.ControlledFormation.Banner = banner;
                        }
                        SpawnComponent   spawnComponent   = this.SpawnComponent;
                        Team             team             = peer.Team;
                        EquipmentElement equipmentElement = equipment[EquipmentIndex.ArmorItemEndSlot];
                        int         num3       = equipmentElement.Item != null ? 1 : 0;
                        int         num4       = peer.SpawnCountThisRound == 0 ? 1 : 0;
                        MatrixFrame spawnFrame = spawnComponent.GetSpawnFrame(team, num3 != 0, num4 != 0);
                        if (!spawnFrame.IsIdentity)
                        {
                            MatrixFrame matrixFrame       = spawnFrame;
                            MatrixFrame?agentInitialFrame = agentBuildData.AgentInitialFrame;
                            if ((agentInitialFrame.HasValue ? (matrixFrame != agentInitialFrame.GetValueOrDefault() ? 1 : 0) : 1) != 0)
                            {
                                agentBuildData.InitialFrame(spawnFrame);
                            }
                        }
                        if (peer.ControlledAgent != null && !isPlayer)
                        {
                            MatrixFrame frame = peer.ControlledAgent.Frame;
                            frame.rotation.OrthonormalizeAccordingToForwardAndKeepUpAsZAxis();
                            MatrixFrame matrixFrame = frame;
                            matrixFrame.origin -= matrixFrame.rotation.f.NormalizedCopy() * 3.5f;
                            Mat3 rotation = matrixFrame.rotation;
                            rotation.MakeUnit();
                            equipmentElement = basicCharacterObject.Equipment[EquipmentIndex.ArmorItemEndSlot];
                            bool flag2 = !equipmentElement.IsEmpty;
                            int  num5  = Math.Min(num2, 10);
                            List <WorldFrame> formationCreation = Formation.GetFormationFramesForBeforeFormationCreation((float)((double)num5 * (double)Formation.GetDefaultUnitDiameter(flag2) + (double)(num5 - 1) * (double)Formation.GetDefaultMinimumInterval(flag2)), num2, flag2, new WorldPosition(Mission.Current.Scene, matrixFrame.origin), rotation);
                            agentBuildData.InitialFrame(formationCreation[index - 1].ToGroundMatrixFrame());
                        }
                        Agent agent = this.Mission.SpawnAgent(agentBuildData, true);
                        agent.AddComponent((AgentComponent) new MPPerksAgentComponent(agent));
                        agent.MountAgent?.UpdateAgentProperties();
                        float num6 = spawnPerkHandler != null?spawnPerkHandler.GetHitpoints(isPlayer) : 0.0f;

                        agent.HealthLimit += num6;
                        agent.Health       = agent.HealthLimit;
                        agent.AddComponent((AgentComponent) new AgentAIStateFlagComponent(agent));
                        if (!isPlayer)
                        {
                            agent.SetWatchState(AgentAIStateFlagComponent.WatchState.Alarmed);
                        }
                        agent.WieldInitialWeapons();
                        if (isPlayer)
                        {
                            Action <MissionPeer> spawnedFromVisuals = this.OnPeerSpawnedFromVisuals;
                            if (spawnedFromVisuals != null)
                            {
                                spawnedFromVisuals(peer);
                            }
                        }
                    }
                    ++peer.SpawnCountThisRound;
                    Action <MissionPeer> spawnedFromVisuals1 = this.OnAllAgentsFromPeerSpawnedFromVisuals;
                    if (spawnedFromVisuals1 != null)
                    {
                        spawnedFromVisuals1(peer);
                    }
                    this.AgentVisualSpawnComponent.RemoveAgentVisuals(peer, true);
                    MPPerkObject.GetPerkHandler(peer)?.OnEvent(MPPerkCondition.PerkEventFlags.SpawnEnd);
                }
            }
            if (this.IsSpawningEnabled || !this.IsRoundInProgress())
            {
                return;
            }
            if ((double)this.SpawningDelayTimer >= (double)this.SpawningEndDelay && !this._hasCalledSpawningEnded)
            {
                Mission.Current.AllowAiTicking = true;
                if (this.OnSpawningEnded != null)
                {
                    this.OnSpawningEnded();
                }
                this._hasCalledSpawningEnded = true;
            }
            this.SpawningDelayTimer += dt;
        }
Exemple #16
0
 private void OnHealthChanged(Agent agent, float oldHealth, float newHealth) => MPPerkObject.GetPerkHandler(this.Agent)?.OnEvent(agent, MPPerkCondition.PerkEventFlags.HealthChange);
        protected override void SpawnAgents()
        {
            BasicCultureObject cultureLimit1 = MBObjectManager.Instance.GetObject <BasicCultureObject>(MultiplayerOptions.OptionType.CultureTeam1.GetStrValue());
            BasicCultureObject cultureLimit2 = MBObjectManager.Instance.GetObject <BasicCultureObject>(MultiplayerOptions.OptionType.CultureTeam2.GetStrValue());

            foreach (MissionPeer peer in VirtualPlayer.Peers <MissionPeer>())
            {
                if (peer.GetNetworkPeer().IsSynchronized&& peer.ControlledAgent == null && (!peer.HasSpawnedAgentVisuals && peer.Team != null) && (peer.Team != this.Mission.SpectatorTeam && peer.SpawnTimer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission))))
                {
                    IAgentVisual       agentVisualForPeer = peer.GetAgentVisualForPeer(0);
                    BasicCultureObject basicCultureObject = peer.Team.Side == BattleSideEnum.Attacker ? cultureLimit1 : cultureLimit2;
                    int num = peer.SelectedTroopIndex;
                    IEnumerable <MultiplayerClassDivisions.MPHeroClass> mpHeroClasses = MultiplayerClassDivisions.GetMPHeroClasses(basicCultureObject);
                    MultiplayerClassDivisions.MPHeroClass mpHeroClass = num < 0 ? (MultiplayerClassDivisions.MPHeroClass)null : mpHeroClasses.ElementAt <MultiplayerClassDivisions.MPHeroClass>(num);
                    if (mpHeroClass == null && num < 0)
                    {
                        mpHeroClass = mpHeroClasses.First <MultiplayerClassDivisions.MPHeroClass>();
                        num         = 0;
                    }
                    BasicCharacterObject heroCharacter = mpHeroClass.HeroCharacter;
                    Equipment            equipment     = heroCharacter.Equipment.Clone();
                    IEnumerable <(EquipmentIndex, EquipmentElement)> alternativeEquipments = MPPerkObject.GetOnSpawnPerkHandler(peer)?.GetAlternativeEquipments(true);
                    if (alternativeEquipments != null)
                    {
                        foreach ((EquipmentIndex, EquipmentElement)tuple in alternativeEquipments)
                        {
                            equipment[tuple.Item1] = tuple.Item2;
                        }
                    }
                    AgentBuildData agentBuildData = new AgentBuildData(heroCharacter);
                    agentBuildData.MissionPeer(peer);
                    agentBuildData.Equipment(equipment);
                    agentBuildData.Team(peer.Team);
                    MatrixFrame frame;
                    if (agentVisualForPeer == null)
                    {
                        frame = this.SpawnComponent.GetSpawnFrame(peer.Team, heroCharacter.Equipment.Horse.Item != null);
                    }
                    else
                    {
                        frame = agentVisualForPeer.GetFrame();
                        frame.rotation.MakeUnit();
                    }
                    agentBuildData.InitialFrame(frame);
                    agentBuildData.IsFemale(peer.Peer.IsFemale);
                    BodyProperties bodyProperties = this.GetBodyProperties(peer, basicCultureObject);
                    agentBuildData.BodyProperties(bodyProperties);
                    agentBuildData.VisualsIndex(0);
                    agentBuildData.ClothingColor1(peer.Team == this.Mission.AttackerTeam ? basicCultureObject.Color : basicCultureObject.ClothAlternativeColor);
                    agentBuildData.ClothingColor2(peer.Team == this.Mission.AttackerTeam ? basicCultureObject.Color2 : basicCultureObject.ClothAlternativeColor2);
                    agentBuildData.TroopOrigin((IAgentOriginBase) new BasicBattleAgentOrigin(heroCharacter));
                    NetworkCommunicator networkPeer = peer.GetNetworkPeer();
                    if (this.GameMode.ShouldSpawnVisualsForServer(networkPeer))
                    {
                        this.AgentVisualSpawnComponent.SpawnAgentVisualsForPeer(peer, agentBuildData, num);
                    }
                    this.GameMode.HandleAgentVisualSpawning(networkPeer, agentBuildData);
                }
            }
            if (this.Mission.AttackerTeam != null)
            {
                int num = 0;
                foreach (Agent activeAgent in this.Mission.AttackerTeam.ActiveAgents)
                {
                    if (activeAgent.Character != null && activeAgent.MissionPeer == null)
                    {
                        ++num;
                    }
                }
                if (num < MultiplayerOptions.OptionType.NumberOfBotsTeam1.GetIntValue())
                {
                    this.SpawnBot(this.Mission.AttackerTeam, cultureLimit1);
                }
            }
            if (this.Mission.DefenderTeam == null)
            {
                return;
            }
            int num1 = 0;

            foreach (Agent activeAgent in this.Mission.DefenderTeam.ActiveAgents)
            {
                if (activeAgent.Character != null && activeAgent.MissionPeer == null)
                {
                    ++num1;
                }
            }
            if (num1 >= MultiplayerOptions.OptionType.NumberOfBotsTeam2.GetIntValue())
            {
                return;
            }
            this.SpawnBot(this.Mission.DefenderTeam, cultureLimit2);
        }
Exemple #18
0
        public override void OnAgentRemoved(
            Agent affectedAgent,
            Agent affectorAgent,
            AgentState agentState,
            KillingBlow blow)
        {
            if (blow.DamageType == DamageTypes.Invalid || agentState != AgentState.Unconscious && agentState != AgentState.Killed || !affectedAgent.IsHuman)
            {
                return;
            }
            if (affectorAgent != null && affectorAgent.IsEnemyOf(affectedAgent))
            {
                this._missionScoreboardComponent.ChangeTeamScore(affectorAgent.Team, this.GetScoreForKill(affectedAgent));
            }
            else
            {
                this._missionScoreboardComponent.ChangeTeamScore(affectedAgent.Team, -this.GetScoreForKill(affectedAgent));
            }
            MissionPeer missionPeer = affectedAgent.MissionPeer;

            if (missionPeer != null)
            {
                int num1 = 100;
                if (affectorAgent != affectedAgent)
                {
                    List <MissionPeer>[] missionPeerListArray = new List <MissionPeer> [2];
                    for (int index = 0; index < missionPeerListArray.Length; ++index)
                    {
                        missionPeerListArray[index] = new List <MissionPeer>();
                    }
                    foreach (NetworkCommunicator networkPeer in GameNetwork.NetworkPeers)
                    {
                        MissionPeer component = networkPeer.GetComponent <MissionPeer>();
                        if (component != null && component.Team != null && component.Team.Side != BattleSideEnum.None)
                        {
                            missionPeerListArray[(int)component.Team.Side].Add(component);
                        }
                    }
                    int            num2           = missionPeerListArray[1].Count - missionPeerListArray[0].Count;
                    BattleSideEnum battleSideEnum = num2 == 0 ? BattleSideEnum.None : (num2 < 0 ? BattleSideEnum.Attacker : BattleSideEnum.Defender);
                    if (battleSideEnum != BattleSideEnum.None && battleSideEnum == missionPeer.Team.Side)
                    {
                        int num3  = Math.Abs(num2);
                        int count = missionPeerListArray[(int)battleSideEnum].Count;
                        if (count > 0)
                        {
                            int num4 = num1 * num3 / 10 / count * 10;
                            num1 += num4;
                        }
                    }
                }
                this.ChangeCurrentGoldForPeer(missionPeer, missionPeer.Representative.Gold + num1);
            }
            MultiplayerClassDivisions.MPHeroClass classForCharacter = MultiplayerClassDivisions.GetMPHeroClassForCharacter(affectedAgent.Character);
            Agent.Hitter assistingHitter = affectedAgent.GetAssistingHitter(affectorAgent?.MissionPeer);
            if (affectorAgent?.MissionPeer != null && affectorAgent != affectedAgent && !affectorAgent.IsFriendOf(affectedAgent))
            {
                TeamDeathmatchMissionRepresentative representative = affectorAgent.MissionPeer.Representative as TeamDeathmatchMissionRepresentative;
                int dataAndUpdateFlags = representative.GetGoldGainsFromKillDataAndUpdateFlags(MPPerkObject.GetPerkHandler(affectorAgent.MissionPeer), MPPerkObject.GetPerkHandler(assistingHitter?.HitterPeer), classForCharacter, false, blow.IsMissile);
                this.ChangeCurrentGoldForPeer(affectorAgent.MissionPeer, representative.Gold + dataAndUpdateFlags);
            }
            if (assistingHitter?.HitterPeer != null && !assistingHitter.IsFriendlyHit)
            {
                TeamDeathmatchMissionRepresentative representative = assistingHitter.HitterPeer.Representative as TeamDeathmatchMissionRepresentative;
                int dataAndUpdateFlags = representative.GetGoldGainsFromKillDataAndUpdateFlags(MPPerkObject.GetPerkHandler(affectorAgent?.MissionPeer), MPPerkObject.GetPerkHandler(assistingHitter.HitterPeer), classForCharacter, true, blow.IsMissile);
                this.ChangeCurrentGoldForPeer(assistingHitter.HitterPeer, representative.Gold + dataAndUpdateFlags);
            }
            if (missionPeer?.Team == null)
            {
                return;
            }
            IEnumerable <(MissionPeer, int)> goldRewardsOnDeath = MPPerkObject.GetPerkHandler(missionPeer)?.GetTeamGoldRewardsOnDeath();

            if (goldRewardsOnDeath == null)
            {
                return;
            }
            foreach ((MissionPeer peer, int baseAmount) in goldRewardsOnDeath)
            {
                if (peer?.Representative is TeamDeathmatchMissionRepresentative representative1)
                {
                    int local_21 = representative1.GetGoldGainsFromAllyDeathReward(baseAmount);
                    if (local_21 > 0)
                    {
                        this.ChangeCurrentGoldForPeer(peer, representative1.Gold + local_21);
                    }
                }
            }
        }