예제 #1
0
        private bool CheckTarget(SmartEntity shooter, SmartEntity target, ref int maxWeight)
        {
            if (shooter == null || target == null)
            {
                return(false);
            }
            TransformComponent transformComp = target.TransformComp;
            TroopComponent     troopComp     = target.TroopComp;

            if (transformComp == null || troopComp == null)
            {
                return(false);
            }
            ShooterComponent shooterComp = shooter.ShooterComp;

            if ((long)GameUtils.GetSquaredDistanceToTarget(shooterComp, target) < (long)((ulong)shooterComp.MinAttackRangeSquared))
            {
                return(false);
            }
            if (TroopController.IsEntityPhantom(target))
            {
                return(false);
            }
            if (shooterComp.OriginalShooterVO.NewTargetOnReload && !shooterComp.IsPotentialTargetNew(target.ID))
            {
                return(false);
            }
            TransformComponent transformComp2 = shooter.TransformComp;
            int squaredDistance = GameUtils.SquaredDistance(transformComp2.CenterGridX(), transformComp2.CenterGridZ(), transformComp.CenterGridX(), transformComp.CenterGridZ());
            int targetNearness  = this.spatialIndexController.CalcNearness(squaredDistance);
            int num             = this.CalculateWeight(shooterComp, null, troopComp.TroopType.ArmorType, targetNearness);

            if (num > maxWeight)
            {
                maxWeight = num;
                return(true);
            }
            return(false);
        }
예제 #2
0
        private SmartEntity GetPrefferedBuilding(ShooterComponent shooterComp, SmartEntityPriorityList buildings, ref int maxWeight)
        {
            HashSet <string> hashSet = new HashSet <string>();
            SmartEntity      result  = null;
            int i     = 0;
            int count = buildings.Count;

            while (i < count)
            {
                SmartEntityElementPriorityPair smartEntityElementPriorityPair = buildings.Get(i);
                SmartEntity element = smartEntityElementPriorityPair.Element;
                if (!shooterComp.ShooterVO.NewTargetOnReload || shooterComp.IsPotentialTargetNew(element.ID))
                {
                    HealthComponent healthComp = element.HealthComp;
                    if (healthComp != null && !healthComp.IsDead())
                    {
                        BuildingComponent buildingComp = element.BuildingComp;
                        if (buildingComp.BuildingType.Type != BuildingType.Blocker)
                        {
                            if (element.TrapComp == null || element.TrapComp.CurrentState == TrapState.Armed)
                            {
                                if (hashSet.Add(buildingComp.BuildingType.BuildingID))
                                {
                                    int num = this.CalculateWeight(shooterComp, null, healthComp.ArmorType, smartEntityElementPriorityPair.Priority);
                                    if (num > maxWeight)
                                    {
                                        maxWeight = num;
                                        result    = element;
                                    }
                                }
                            }
                        }
                    }
                }
                i++;
            }
            return(result);
        }