Ejemplo n.º 1
0
        public static LaunchEvent FromJson(string jsonString)
        {
            DeserializedLaunchEvent parsed = JsonConvert.DeserializeObject <DeserializedLaunchEvent>(jsonString);

            GameTick currentTick = Game.TimeMachine.GetCurrentTick();
            GameTick eventTick   = GameTick.FromTickNumber(parsed.GameTick);

            // Go to the time the event occurred.
            Game.TimeMachine.GoTo(eventTick);
            GameState state = Game.TimeMachine.GetState();

            ILaunchable source = state.GetOutpostById(parsed.Source);

            if (source == null)
            {
                source = state.GetSubById(parsed.Source);
            }

            ICombatable destination = state.GetOutpostById(parsed.Destination);

            if (destination == null)
            {
                destination = state.GetSubById(parsed.Destination);
            }

            Game.TimeMachine.GoTo(currentTick);

            return(new LaunchEvent(eventTick, source, parsed.Drillers, destination));
        }
Ejemplo n.º 2
0
        public override async Task <DougResponse> Activate(User user, ICombatable target, string channel)
        {
            if (!CanActivateSkill(user, out var response))
            {
                return(response);
            }

            if (target == null)
            {
                return(new DougResponse());
            }

            if (target is User targetUser)
            {
                var channelType = _channelRepository.GetChannelType(channel);
                if (channelType != ChannelType.Common && channelType != ChannelType.Pvp)
                {
                    return(new DougResponse(DougMessages.NotInRightChannel));
                }

                var usersInChannel = await _slack.GetUsersInChannel(channel);

                if (usersInChannel.All(usr => usr != targetUser.Id))
                {
                    return(new DougResponse(DougMessages.UserIsNotInPvp));
                }

                response = await StealFromUser(user, targetUser, channel);
            }

            return(response);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Reverses a specialist effect to a friendly and enemy combatable
 /// </summary>
 /// <param name="friendly">The friendly combatable to reverse effects to</param>
 /// <param name="enemy">The enemy combatable to reverse effects to</param>
 public void UndoEffect(ICombatable friendly, ICombatable enemy)
 {
     foreach (ISpecialistEffect effect in this._specialistEffects)
     {
         effect.BackwardEffect(friendly, enemy);
     }
 }
Ejemplo n.º 4
0
        protected virtual bool CanActivateSkill(User user, ICombatable target, string channel, out DougResponse response)
        {
            var totalCooldown = Cooldown * (1 - user.CooldownReduction());

            if (!user.HasWeaponType(RequiredWeapon) && RequiredWeapon != null)
            {
                response = new DougResponse(string.Format(DougMessages.WrongWeaponForSkill, RequiredWeapon.Name));
                return(false);
            }

            if (user.IsSkillOnCooldown())
            {
                response = new DougResponse(string.Format(DougMessages.CommandOnCooldown, user.CalculateStealCooldownRemaining()));
                return(false);
            }

            if (!user.HasEnoughEnergyForCost(EnergyCost))
            {
                response = new DougResponse(DougMessages.NotEnoughEnergy);
                return(false);
            }

            user.Energy -= EnergyCost;
            StatsRepository.FireSkill(user.Id, TimeSpan.FromSeconds(totalCooldown), user.Energy);
            response = new DougResponse();
            return(true);
        }
Ejemplo n.º 5
0
    public void Fight(ICombatable attacker, ICombatable defender)
    {
        int damage = CalculateAttackerDamage(attacker, defender);

        attacker.OnAttack(defender);
        attacker.CurrentActionPoints -= attacker.AttackActionPointCost;
        defender.CurrentHealth       -= damage;

        if (defender.CurrentHealth <= 0)
        {
            defender.OnDeath();
        }
        else if (defender.CanRetaliate())
        {
            int dist = HexHeuristic.MinDistTile(defender.Tile, attacker.Tile);
            if (dist > defender.Range)
            {
                return;
            }

            damage = CalculateDefenderDamage(defender);
            defender.OnAttack(attacker);
            attacker.CurrentHealth -= damage;
            if (attacker.CurrentHealth <= 0)
            {
                attacker.OnDeath();
            }
        }
    }
Ejemplo n.º 6
0
        internal static void Resolve(ICombatable attacking, ICombatable defending)
        {
            var combatResult = Resolve(new ArmiesPair(attacking.Army, defending.Army));

            attacking.SetArmy(combatResult.AttackingArmy);
            defending.SetArmy(combatResult.DefendingArmy);
        }
Ejemplo n.º 7
0
        public void CreateArmy(ICombatable army, Location location)
        {
            var armyType = GetArmyType(army);

            engine.CreateObject(army.UnityId, armyType, location.X, location.Y);
            engine.SetRotation(army.UnityId, random.ChoiceWithProbability(0.5, Mathf.PI / 3, 2 * Mathf.PI / 3));
        }
Ejemplo n.º 8
0
        protected override bool CanActivateSkill(User user, ICombatable target, string channel, out DougResponse response)
        {
            var totalCooldown = Cooldown * (1 - user.CooldownReduction());

            if (target is User targetUser)
            {
                var usersInChannel = _slack.GetUsersInChannel(channel).Result;
                if (usersInChannel.All(usr => usr != targetUser.Id))
                {
                    response = new DougResponse(DougMessages.UserNotInChannel);
                    return(false);
                }
            }

            if (user.IsSkillOnCooldown())
            {
                response = new DougResponse(string.Format(DougMessages.CommandOnCooldown, user.CalculateStealCooldownRemaining()));
                return(false);
            }

            if (!user.HasEnoughEnergyForCost(EnergyCost))
            {
                response = new DougResponse(DougMessages.NotEnoughEnergy);
                return(false);
            }

            user.Energy -= EnergyCost;
            StatsRepository.FireSkill(user.Id, TimeSpan.FromSeconds(totalCooldown), user.Energy);
            response = new DougResponse();
            return(true);
        }
Ejemplo n.º 9
0
        public override DougResponse Activate(User user, ICombatable target, string channel)
        {
            if (!CanActivateSkill(user, out var response))
            {
                return(response);
            }

            var userToBeHealed = user;

            if (target != null && target is User targetUser)
            {
                userToBeHealed = targetUser;
            }

            var healAmount = 30; // TODO : add scaling

            userToBeHealed.Health += healAmount;
            StatsRepository.UpdateHealth(userToBeHealed.Id, userToBeHealed.Health);

            var message = string.Format(DougMessages.UserHealed, _userService.Mention(user), _userService.Mention(userToBeHealed), healAmount);

            _slack.BroadcastMessage(message, channel);

            return(new DougResponse());
        }
Ejemplo n.º 10
0
        public bool BackwardAction(TimeMachine timeMachine, GameState state)
        {
            if (!_eventSuccess)
            {
                return(false);
            }

            List <Specialist> specialists = new List <Specialist>();

            specialists.AddRange(_combatant1Specialists);
            specialists.AddRange(_combatant2Specialists);

            while (specialists.Count > 0)
            {
                Specialist lowPriority = null;
                foreach (Specialist s in specialists)
                {
                    if (lowPriority == null || s.GetPriority() >= lowPriority.GetPriority())
                    {
                        lowPriority = s;
                    }
                }
                // Apply the specialist effect to the enemey.
                ICombatable enemy    = _combatant1.GetOwner() == lowPriority.GetOwner() ? _combatant2 : _combatant1;
                ICombatable friendly = _combatant1.GetOwner() == lowPriority.GetOwner() ? _combatant1 : _combatant2;
                lowPriority.UndoEffect(friendly, enemy);
            }
            return(true);
        }
Ejemplo n.º 11
0
        public bool ForwardAction(TimeMachine timeMachine, GameState state)
        {
            this._combatant1Specialists = _combatant1.GetSpecialistManager().GetSpecialists();
            this._combatant2Specialists = _combatant1.GetSpecialistManager().GetSpecialists();

            List <Specialist> specialists = new List <Specialist>();

            specialists.AddRange(_combatant1.GetSpecialistManager().GetSpecialists());
            specialists.AddRange(_combatant2.GetSpecialistManager().GetSpecialists());

            while (specialists.Count > 0)
            {
                Specialist topPriority = null;
                foreach (Specialist s in specialists)
                {
                    // If any of the specialists are invalid, cancel the event.
                    if (!Validator.ValidateSpecialist(s))
                    {
                        this._eventSuccess = false;
                        return(false);
                    }
                    if (topPriority == null || s.GetPriority() < topPriority.GetPriority())
                    {
                        topPriority = s;
                    }
                }
                // Apply the specialist effect to the enemey.
                ICombatable enemy    = _combatant1.GetOwner() == topPriority.GetOwner() ? _combatant2 : _combatant1;
                ICombatable friendly = _combatant1.GetOwner() == topPriority.GetOwner() ? _combatant1 : _combatant2;
                topPriority.ApplyEffect(friendly, enemy);
            }
            return(true);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Applies the specialist's effects to a friendly and enemy combatable.
 /// </summary>
 /// <param name="friendly">The friendly combatable to effect</param>
 /// <param name="enemy">The enemy combatable to effect</param>
 public void ApplyEffect(ICombatable friendly, ICombatable enemy)
 {
     foreach (ISpecialistEffect effect in this._specialistEffects)
     {
         effect.ForwardEffect(friendly, enemy);
     }
 }
Ejemplo n.º 13
0
        public string Defend(ICombatable subject)
        {
            int defendValue = maxLevel - subject.Level;

            this.Health = -defendValue;

            return("Defending.");
        }
Ejemplo n.º 14
0
        public override int OnAttacking(User attacker, ICombatable target, int damage)
        {
            attacker.Health += (int)(damage * 0.05);

            _statsRepository.UpdateHealth(attacker.Id, attacker.Health);

            return(base.OnAttacking(attacker, target, damage));
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Constructor for the combat event
 /// </summary>
 /// <param name="combatant1">The first combatant</param>
 /// <param name="combatant2">The second combatant</param>
 /// <param name="tick">The tick the combat occurs</param>
 /// <param name="combatLocation">The location of the combat</param>
 public CombatEvent(ICombatable combatant1, ICombatable combatant2, GameTick tick, RftVector combatLocation)
 {
     this._combatant1     = combatant1;
     this._combatant2     = combatant2;
     this._eventTick      = tick;
     this._combatLocation = combatLocation;
     this.EventName       = "Combat Event";
 }
 // Use this for initialization
 void Start()
 {
     m_combatable = GetComponent <ICombatable>();
     m_timer      = new Timer(1f, true, () => {
         m_timer.ResetTimer();
         m_combatable.CombatStats.Shields += m_combatable.CombatStats.ShieldRegen;
     });
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Constructor for a sub launch event.
 /// </summary>
 /// <param name="launchTime">The time of the launch</param>
 /// <param name="source">The source</param>
 /// <param name="drillerCount">The number of drillers to send</param>
 /// <param name="destination">The destination</param>
 public LaunchEvent(GameTick launchTime, ILaunchable source, int drillerCount, ICombatable destination)
 {
     this._launchTime   = launchTime;
     this._source       = source;
     this._drillerCount = drillerCount;
     this._destination  = destination;
     this.EventName     = "Launch Event";
 }
Ejemplo n.º 18
0
 private double BeginCombat(ICombatable other, Tile robotTile, Tile otherTile)
 {
     return(new CombatHelper(robot).BeginCombat(other, robotTile, otherTile, () =>
     {
         robot.ControlTrigger.ScheduledTime = world.Clocks.CurrentTime + movementDuration + 0.001;
         MakeTurn(robot);
     }));
 }
Ejemplo n.º 19
0
        public AttackedEventArgs(ICombatable attacker, ICombatable target, double rawDammage)
        {
            Attacker = attacker;

            Target = target;

            RawDammage = rawDammage;
        }
Ejemplo n.º 20
0
 public virtual void OnAttack(ICombatable target)
 {
     if (projectilePrefab != null)
     {
         Projectile instance  = Instantiate(projectilePrefab, transform.position, transform.rotation);
         Vector3    targetPos = new Vector3(target.PosX, target.PosY, target.PosZ);
         instance.Initialize(targetPos);
     }
 }
Ejemplo n.º 21
0
        public async Task <DougResponse> ActivateSkill(User user, ICombatable target, string channel)
        {
            if (user.Loadout.Skillbook == null)
            {
                return(new DougResponse(DougMessages.NoSkillEquipped));
            }

            return(await user.Loadout.Skillbook.Activate(_skillFactory, user, target, channel));
        }
 public override bool BackwardAction(TimeMachine timeMachine, GameState state)
 {
     if (EventSuccess)
     {
         ICombatable source = state.GetCombatableById(GetEventData().SourceId);
         source.GetShieldManager().ToggleShield();
     }
     return(EventSuccess);
 }
Ejemplo n.º 23
0
 public void ReceiveDamage(ICombatable damageDealer, float damage)
 {
     health -= damage;
     if (health <= 0)
     {
         Died?.Invoke(this);
         Destroy(this.gameObject);
     }
 }
Ejemplo n.º 24
0
        public PhysicalAttack(ICombatable attacker, int minDamage, int maxDamage, int attackersHitrate, int attackersLuck) : base(RollAttack(minDamage, maxDamage), attacker)
        {
            AttackersHitrate = attackersHitrate;

            if (new Random().NextDouble() < Math.Sqrt(attackersLuck) * 0.04)
            {
                Status = AttackStatus.Critical;
            }
        }
Ejemplo n.º 25
0
        public int OnCriticalHit(ICombatable attacker, ICombatable target, int damage, string channel)
        {
            if (attacker is User userAttacker)
            {
                damage = PropagateEffectEvents(userAttacker, damage, (damageSum, effect) => effect.OnCriticalHit(userAttacker, target, damageSum, channel));
            }

            return(damage);
        }
Ejemplo n.º 26
0
 public static bool HasNoArmy(this ICombatable c)
 {
     foreach (var stack in c.Army)
     {
         if (stack.Value > 0)
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 27
0
        public Attack AttackTarget(ICombatable target, IEventDispatcher eventDispatcher)
        {
            Attack attack = new PhysicalAttack(this, Monster.MinAttack, Monster.MaxAttack, Monster.Hitrate, Monster.GetCriticalHitChance(), 2, 0);

            if (Monster.DamageType == DamageType.Magical)
            {
                attack = new MagicAttack(this, Monster.MaxAttack);
            }

            return(target.ReceiveAttack(attack, eventDispatcher));
        }
Ejemplo n.º 28
0
 public async Task DealDamage(User user, Attack attack, ICombatable target, string channel)
 {
     if (target is User targetUser)
     {
         await DealDamageToUser(user, attack, targetUser, channel);
     }
     else if (target is SpawnedMonster targetMonster)
     {
         await DealDamageToMonster(user, attack, targetMonster, channel);
     }
 }
Ejemplo n.º 29
0
        public Attack AttackTarget(ICombatable target, IEventDispatcher eventDispatcher)
        {
            Attack attack = new PhysicalAttack(this, MinAttack, MaxAttack, Hitrate, Luck);

            if (DamageType == DamageType.Magical)
            {
                attack = new MagicAttack(this, Intelligence);
            }

            return(target.ReceiveAttack(attack, eventDispatcher));
        }
Ejemplo n.º 30
0
        public PhysicalAttack(ICombatable attacker, int minDamage, int maxDamage, int attackersHitrate, double criticalHitChance, double criticalFactor, int pierce) : base(RollAttack(minDamage, maxDamage), attacker)
        {
            AttackersHitrate = attackersHitrate;
            CriticalFactor   = criticalFactor;
            Pierce           = pierce;

            if (new Random().NextDouble() < criticalHitChance)
            {
                Status = AttackStatus.Critical;
            }
        }