Example #1
0
        public override void Update()
        {
            if (Units.Count() == 0)
            {
                return;
            }

            GuardedUnits.RemoveAll(u => !u.Targetable);

            if (GuardedUnits.Count == 0)
            {
                return;
            }

            var units = Units.ToList();

            for (int i = 0; i < units.Count; i++)
            {
                var unit  = units[i];
                var guard = GuardedUnits[unit.Id % GuardedUnits.Count];
                var pos   = guard.Position + Position.FromPolar(2 * Math.PI * i / units.Count, 2);

                if (unit.Position.DistanceTo(pos) > 0.3)
                {
                    unit.TargetPosition(pos, UnitAction.MOVE, null, null);
                }

                guard.RequestUpdate();
            }
        }
Example #2
0
        public Message PlayerAttack(Position coordinates, Guid playerId)
        {
            //check if its player turn and that the game is active
            if (Turn != playerId || !this.PlayingNow)
            {
                return new Message {
                           Action = GameAction.ShotMissed, Player1 = Player1, Player2 = Player2, Command = Command.NotYourTurn, MatchId = MatchId
                }
            }
            ;

            //determine if its a hit
            var  unit = Units.FirstOrDefault(u => u.Row == coordinates.Row && u.Column == coordinates.Column && u.PlayerId != playerId);
            bool wasHit;

            if (unit != null && unit.Health > 0)
            {
                //update the unit status, and queue a message
                unit.TakeDamage(1);

                UpdateUnit(columns: new { Health = unit.Health }, where : new { MatchId = unit.MatchId, And_UnitId = unit.UnitId, And_PlayerId = unit.PlayerId });
                wasHit = true;
            }
            else
            {
                wasHit = false;
            }
            //queue proper message
            if (wasHit)
            {
                //check if player won the match
                if (Units.Count(u => u.Health > 0 && u.PlayerId != playerId) == 0)
                {
                    //inform players the match result
                    return(MatchFinished(winner: playerId, losser: unit.PlayerId));
                }
                else
                {
                    //inform the hit
                    var msg = new Message {
                        Action = GameAction.ShotMade, Player1 = Player1, Player2 = Player2, Command = Command.GameAction, HealthAfterAttack = unit.Health, MatchId = MatchId, UnitId = unit.UnitId, Coordinates = coordinates
                    };
                    return(msg);
                }
            }
            else
            {
                //inform the missing
                var msg = new Message {
                    Action = GameAction.ShotMissed, Player1 = Player1, Player2 = Player2, Command = Command.GameAction, MatchId = MatchId, Coordinates = coordinates
                };

                //change the turn
                Turn = Turn == Player1 ? Player2 : Player1;
                UpdateMatch();
                return(msg);
            }
        }
 private void UpdateForceOrgCount()
 {
     HqCount           = Units.Count(u => u.Unit.ForceOrgSlot == 0 && u.Unit.CountsTowardForceOrg);
     TroopCount        = Units.Count(u => u.Unit.ForceOrgSlot == 1 && u.Unit.CountsTowardForceOrg);
     EliteCount        = Units.Count(u => u.Unit.ForceOrgSlot == 2 && u.Unit.CountsTowardForceOrg);
     FastAttackCount   = Units.Count(u => u.Unit.ForceOrgSlot == 3 && u.Unit.CountsTowardForceOrg);
     HeavySupportCount = Units.Count(u => u.Unit.ForceOrgSlot == 4 && u.Unit.CountsTowardForceOrg);
     LordOfWarCount    = Units.Count(u => u.Unit.ForceOrgSlot == 5 && u.Unit.CountsTowardForceOrg);
 }
        // רשימת מארחים מקובצת )Grouping )ע"פ מספר יחידות האירוח שהם מחזיקים
        public IEnumerable <IGrouping <int, Host> > GetGroupingHostByNumOfHostingUnit()
        {
            var hostingUnits = dal.getAllHostingUnits();

            return(from Unit in hostingUnits
                   group Unit by Unit.Owner.HostKey into Units
                   let Owner = Units.FirstOrDefault().Owner
                               let num_of_Unit = Units.Count()
                                                 group Owner by num_of_Unit);
        }
Example #5
0
        public string ToString(string format)
        {
            FindDerivedUnits();
            format = format.ToLower();
            string quantity   = !format.Contains("i") ? Quantity.ToString() : ""; // ignore quantity
            bool   fancy      = !format.Contains("c");                            // common formmating
            bool   useDivisor = !format.Contains("d");                            // use '/'
            bool   baseOnly   = format.Contains("b");                             // base units only
            string unitString = "";

            if (baseOnly)
            {
                unitString = Stringifier.MultipleUnitsToString(Unit.Multiply(Units.ToArray()).SelectMany(x => x), fancy, useDivisor);
            }
            else if (string.IsNullOrEmpty(UnitName) && Units.Count() > 0)
            {
                unitString = Stringifier.MultipleUnitsToString(Units, fancy, useDivisor);
            }
            else if (!string.IsNullOrEmpty(UnitName))
            {
                unitString = Stringifier.UnitToString(Prefix, UnitName, Power, fancy);
            }
            return(string.Format("{0}{1}", quantity, unitString));
        }
Example #6
0
 public int AliveCount()
 {
     return(Units.Count(u => ((Unit)u).IsAlive));
 }
 public override string ToString()
 {
     return($"Countries : {Countries.Count()}\nProduct Types : {ProductTypes.Count()}\nFBOTypes : {FBOTypes.Count()}\nUnits : {Units.Count()}\nNotifier Types : {NotifierTypes.Count()}");
 }
Example #8
0
        public override void Update()
        {
            if (Units.Count() == 0)
            {
                return;
            }

            var foundations = new Dictionary <int, Unit>();
            var builders    = new HashSet <Unit>();

            foreach (var unit in Units.ToList())
            {
                if (unit.GetData(ObjectData.STATUS) == 0 && unit.GetData(ObjectData.CATEGORY) == 80)
                {
                    foundations.Add(unit.Id, unit);
                }
                else if (unit.GetData(ObjectData.CMDID) == (int)CmdId.VILLAGER)
                {
                    builders.Add(unit);
                }
                else
                {
                    RemoveUnit(unit);
                }
            }

            Manager.Unary.Log.Info($"BuildOperation with {builders.Count} builders");

            foreach (var builder in builders.ToList())
            {
                if (foundations.TryGetValue(builder.GetData(ObjectData.TARGET_ID), out Unit foundation))
                {
                    foundations.Remove(foundation.Id);
                    builders.Remove(builder);
                }
            }

            foreach (var builder in builders)
            {
                if (foundations.Count > 0)
                {
                    var best = foundations.Values.First();
                    var cost = double.MaxValue;

                    foreach (var foundation in foundations.Values)
                    {
                        var c = builder.Position.DistanceTo(foundation.Position);
                        if (c < cost)
                        {
                            best = foundation;
                            cost = c;
                        }
                    }

                    builder.TargetUnit(best, UnitAction.DEFAULT, UnitFormation.LINE, UnitStance.NO_ATTACK);
                    foundations.Remove(best.Id);
                }
                else
                {
                    RemoveUnit(builder);
                }
            }
        }
Example #9
0
        public override void Update()
        {
            if (Units.Count() == 0)
            {
                return;
            }

            if (EnemyPriorities.Count == 0)
            {
                return;
            }

            var enemies = EnemyPriorities.Keys
                          .OrderBy(e => e[ObjectData.HITPOINTS])
                          .ThenBy(e => e.Id)
                          .ToList();


            var target = enemies[0];
            var backup = enemies.Count > 1 ? enemies[1] : target;

            Manager.Unary.Log.Info($"BattleOperation: {Units.Count()} units");
            Manager.Unary.Log.Info($"BattleOperation: Targeting {target.Id}");

            var hp_remaining = new Dictionary <Unit, double>();

            foreach (var enemy in EnemyPriorities.Keys)
            {
                hp_remaining[enemy] = enemy[ObjectData.HITPOINTS];
            }

            foreach (var unit in Units)
            {
                var attack = unit[ObjectData.BASE_ATTACK];
                var armor  = unit[ObjectData.RANGE] > 2 ? target[ObjectData.PIERCE_ARMOR] : target[ObjectData.STRIKE_ARMOR];
                var dmg    = 0.8 * Math.Max(1, attack - armor);
                var delay  = Manager.Unary.Mod.GetAttackDelay(unit[ObjectData.UPGRADE_TYPE]);

                if (target[ObjectData.RANGE] > 2 && unit[ObjectData.RANGE] > 2)
                {
                    var angle = GetDodgeAngle(unit, target);
                    var pos   = unit.Position + (target.Position - unit.Position).Rotate(angle);

                    unit.TargetPosition(pos, UnitAction.MOVE, null, null, 0, unit[ObjectData.RELOAD_TIME] - (int)delay.TotalMilliseconds);
                }

                if (hp_remaining[target] > 0)
                {
                    unit.TargetUnit(target, null, null, null, 0, 0, backup);
                    hp_remaining[target] -= dmg;
                }
                else
                {
                    unit.TargetUnit(backup, null, null, null, 0, 0, target);
                    hp_remaining[backup] -= dmg;
                }
            }

            foreach (var enemy in EnemyPriorities.Keys)
            {
                enemy.RequestUpdate();
            }
        }
Example #10
0
 public int AmountUnits() => Units.Count();