Ejemplo n.º 1
0
        private void ApplyWeaponfireHit(MappedBot victim, CombatResult cr)
        {
            ApplyDamageToObject(victim.EngineId, cr.TotalDamage, DamageType.Projectile);

            bd2TickAction ta = new bd2TickAction();

            ta.ActionType = LastTickEventType.Shot;

            CreateNextTurnNotificationMessage(victim.EngineId, ta);
        }
Ejemplo n.º 2
0
        public CombatResult ResolveAttack(CombatAttack ca)
        {
            if (ca == null)
            {
                throw new BdBaseException("Can not resolve an attack without a combat attack");
            }
            ca.Validate();
            CombatResult result = new CombatResult();

            bool canHit = true;

            if (!ca.Victim.IsAlive())
            {
                canHit = false;
            }

            if ((canHit) && (!map.IsLOSBetween(ca.Attacker.Position, ca.Victim.Position)))
            {
                b.Verbose.Log(string.Format("WeaponFire ({0} --> {1}) - Miss, No Line of sight.", ca.Attacker.Bot.Name, ca.Victim.Bot.Name));
                canHit = false;
            }

            if ((canHit) && (!Calcs.CanMountPointHitTarget(ca.Attacker.Heading, ca.WeaponInstance.MountPoint, ca.Attacker.Position, ca.Victim.Position)))
            {
                b.Verbose.Log(string.Format("WeaponFire ({0} --> {1}) - Miss, Mountpoint Cant Target.", ca.Attacker.Bot.Name, ca.Victim.Bot.Name));
                canHit = false;
            }

            if (!canHit)
            {
                result.DidHit      = false;
                result.TotalDamage = 0;
            }
            else
            {
                double hC = ca.Weapon.BaseHitChance;
                hC += GetSpeedModifier(ca.Attacker.Speed, ca.Victim.Speed);
                hC += GetDistanceModifier(map.GetDistanceBetween(ca.Attacker.Position, ca.Victim.Position));

                result.DidHit = Calcs.DidAchievePercentage(hC);
                b.Info.Log(string.Format("WeaponFire ({0} --> {1}) - Hit Chance {2} - Hit : {3}", ca.Attacker.Bot.Name, ca.Victim.Bot.Name, hC, result.DidHit));
                if (result.DidHit)
                {
                    result.TotalDamage = Calcs.D10Rolls(ca.Weapon.D10DamageRolls);
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        private EquipmentUseResult PerformFireWeapon(OffensiveWeaponEquipmentItem owi, ActiveEquipment activeEquipmentInstance, MappedBot attacker, EquipmentUseRequestContext ctxt)
        {
            EquipmentUseResult result = new EquipmentUseResult();

            if (activeEquipmentInstance.CooldownTicksRemaining > 0)
            {
                result.State = UsageEndState.Fail_CooldownActive;
                return(result);
            }

            MappedBot victim = ConvertTemporaryScanKeyToBot(attacker.EngineId, ctxt.IParam);

            if (victim == null)
            {
                result.State = UsageEndState.Fail_InvalidTarget;
                b.Warning.Log("The bot tried to target an invalid key.  This shouldnt happen");
                return(result);
            }

            b.Assert.True(attacker.EngineId != victim.EngineId, "You cant shoot at yourself.");

            activeEquipmentInstance.RoundsRemaining -= 1;
            if (activeEquipmentInstance.RoundsRemaining <= 0)
            {
                result.State = UsageEndState.Fail_NoAmmo;
                return(result);
            }

            if (!attacker.ConsumeCharge(owi.BaseChargeCost))
            {
                result.State = UsageEndState.Fail_NoCharge;
                return(result);
            }

            CombatAttack ca = new CombatAttack();

            ca.Attacker       = attacker;
            ca.Victim         = victim;
            ca.Weapon         = owi;
            ca.WeaponInstance = activeEquipmentInstance;
            CombatResult cr = combatCore.ResolveAttack(ca);

            UICombatContext context = new UICombatContext();

            context.AggressorId  = attacker.EngineId;
            context.VictimId     = victim.EngineId;
            context.WeaponTypeId = owi.UniqueId;
            context.DidHit       = cr.DidHit;
            context.Damage       = cr.TotalDamage;

            hub.Launch <Message_Ui>(new Message_Ui(MainMessageKind.UIMessage, KnownSubkinds.WeaponFire)
            {
                RequestContext = context
            });

            if (cr.DidHit)
            {
                ApplyWeaponfireHit(victim, cr);
            }

            result.State = UsageEndState.Success;
            return(result);
        }