Ejemplo n.º 1
0
        protected static bool ShieldBlocks(Thing caster, Verb verb, IntVec3 source, LocalTargetInfo target)
        {
            if (caster.Faction == null)
            {
                return(false);
            }
            if (!Mod.Settings.EnableAIVerbFindShotLine)
            {
                return(false);
            }
            if (!verb.verbProps.requireLineOfSight)
            {
                return(false);
            }
            if (UncheckedTypes.Exists(a => a.IsInstanceOfType(verb)))
            {
                return(false);
            }

            var friendlyShieldBlocks = new FieldQuery(caster.Map)
                                       .IsActive()
                                       .FriendlyTo(caster.Faction)
                                       .Intersects(
                PositionUtility.ToVector3(source),
                PositionUtility.ToVector3(target.Cell))
                                       .Get()
                                       .Any();

            return(friendlyShieldBlocks);
        }
Ejemplo n.º 2
0
 protected static bool ShouldStopHighDamage(IntVec3 center, Map map)
 {
     return(new FieldQuery(map)
            .IsActive()
            .Intersects(PositionUtility.ToVector3(center))
            .Block(Mod.Settings.SkyfallerDamage));
 }
        private static float CalculateShieldPreference(float score, Map map, IntVec3 start, IntVec3 end)
        {
            if (!Mod.Settings.EnableAICastPositionFinder)
            {
                return(score);
            }

            var shieldManager = ShieldManager.For(map);

            var startAdjusted = PositionUtility.ToVector3(start);
            var endAdjusted   = PositionUtility.ToVector3(end);

            var targetProtected    = shieldManager.Query(map).IsActive().Intersects(startAdjusted, endAdjusted).Get().ToList();
            var shooterProtected   = shieldManager.Query(map).IsActive().Intersects(endAdjusted, startAdjusted).Get().ToList();
            var shooterUnderShield = shieldManager.Query(map).IsActive().Intersects(startAdjusted).Get().ToList();

            if (shooterProtected.Any())
            {
                score *= 1 + shooterProtected.Count;
            }

            if (shooterUnderShield.Any())
            {
                score *= 1 + shooterUnderShield.Count;
            }

            if (targetProtected.Any())
            {
                score /= 1 + targetProtected.Count;
            }
            return(score);
        }
Ejemplo n.º 4
0
    /// <summary>
    /// 有限状态机状态进入时调用。
    /// </summary>
    /// <param name="fsm">有限状态机引用。</param>
    protected override void OnEnter(IFsm <Monster> fsm)
    {
        base.OnEnter(fsm);

        hurtTimeCounter = 0;

        // 积累受伤次数
        if (preHurtTime != 0 && Time.time - preHurtTime < 2.5f)
        {
            hurtTimes++;
        }
        else
        {
            preHurtTime = 0;
            hurtTimes   = 0;
        }

        // 累积受伤3次,则向后弹一段距离
        if (hurtTimes == 3)
        {
            Vector3 pos = PositionUtility.GetAjustPositionWithMap(fsm.Owner.CachedTransform.position - fsm.Owner.CachedTransform.forward * 2);
            fsm.Owner.CachedTransform.DOMove(pos, 0.5f);
            hurtTimes = 0;
        }

        // 播放动画
        fsm.Owner.ChangeAnimation(FightEntityAnimationState.hurt);

        // 执行受伤逻辑
        int damageHP = fsm.GetData <VarInt> (Constant.EntityData.DamageHP).Value;

        fsm.Owner.OnDamage(damageHP);

        preHurtTime = Time.time;
    }
Ejemplo n.º 5
0
        /// <summary>
        /// 定位以及 刷新Bluebar
        /// </summary>
        /// <returns></returns>
        private async Task FreshBlueBar()
        {
            //先定位以便获取位置信息
            //await LocationNowAsync();
            GeoPosition = await PositionUtility.GetFixedGeopointAsync();

            Map.Center = GeoPosition;

            var blueBarResult = await OfoApi.GetBlueBarAsync(GeoPosition.Position);

            if (await CheckOfoApiResult(blueBarResult))
            {
                BlueBarInfo = blueBarResult.Data;
                if (!string.IsNullOrEmpty(blueBarResult.Data.Text))
                {
                    BlueBarButtonVisibility = Visibility.Visible;
                    if (BlueBarInfo.Id?.Equals(Global.AppConfig.LastBlueBarID) == false)
                    {
                        Global.AppConfig.LastBlueBarID = BlueBarInfo.Id;
                        BlueBarButtonVisibility        = Visibility.Collapsed;
                        BlueBarVisibility = Visibility.Visible;
                        Global.SaveAppConfig();
                    }
                }
            }
        }
Ejemplo n.º 6
0
 protected static bool ShouldStopLowDamage(IntVec3 center, Map map)
 {
     return(new FieldQuery(map)
            .IsActive()
            .Intersects(PositionUtility.ToVector3(center))
            .Block(Mod.Settings.DropPodDamage / 8f));
 }
Ejemplo n.º 7
0
    IEnumerator Chargers()
    {
        while (true)
        {
            while (SaveGame.RoundScore < 5)
            {
                yield return(null);
            }

            const float WarnDelay = 0.5f;

            // Warn player
            AudioManager.Instance.PlayClip(AudioManager.Instance.MiscAudioSource, AudioManager.Instance.AudioData.ChargerWarning);
            yield return(new WaitForSeconds(WarnDelay));

            int amount = 1 + (SaveGame.RoundScore / 15);
            if (Random.value < 0.1f)
            {
                amount += 1;
            }

            PositionUtility.SpawnDirection dir = PositionUtility.GetRandomDirOutside();

            yield return(PositionUtility.SpawnGroup(ActorTypeEnum.SmallCharger, amount, 0.1f, true, dir));

            // Wait semi-random after spawning
            float delay = 12 + Random.value * 2;
            yield return(new WaitForSeconds(delay));
        }
    }
Ejemplo n.º 8
0
        private static float CalculateShieldPreference(float score, Map map, IntVec3 start, IntVec3 end)
        {
            if (!Mod.Settings.EnableAICastPositionFinder)
            {
                return(score);
            }

            var shieldManager = map.GetComponent <ShieldManager>();

            var startAdjusted = PositionUtility.ToVector3(start);
            var endAdjusted   = PositionUtility.ToVector3(end);

            var targetProtected    = shieldManager.WhichShielded(startAdjusted, endAdjusted).ToList();
            var shooterProtected   = shieldManager.WhichShielded(endAdjusted, startAdjusted).ToList();
            var shooterUnderShield = shieldManager.WhichShielded(startAdjusted).ToList();

            if (shooterProtected.Any())
            {
                score *= 1 + shooterProtected.Count;
            }

            if (shooterUnderShield.Any())
            {
                score *= 1 + shooterUnderShield.Count;
            }

            if (targetProtected.Any())
            {
                score /= 1 + targetProtected.Count;
            }
            return(score);
        }
Ejemplo n.º 9
0
 protected static bool IsShielded(IntVec3 position, Map map)
 {
     return(new FieldQuery(map)
            .IsActive()
            .Intersects(PositionUtility.ToVector3(position))
            .Get()
            .Any());
 }
Ejemplo n.º 10
0
        private static bool CanPhysicallyDropIntoShielded(Map map, IntVec3 c)
        {
            var shieldProtected = new FieldQuery(map)
                .Intersects(PositionUtility.ToVector3(c))
                .Get()
                .Any();

            return !shieldProtected;
        }
Ejemplo n.º 11
0
 // Use this for initialization
 void Start()
 {
     Utility1  = FindObjectOfType <PositionUtility>();
     Tester2   = FindObjectOfType <PositionTester2>();
     lm        = FindObjectOfType <LifeManager>();
     turn      = FindObjectOfType <TurnManager>();
     isAbility = false;
     input     = GetComponent <InputController>();
 }
Ejemplo n.º 12
0
 static float Postfix(float __result, IAttackTarget target, IAttackTargetSearcher searcher, Verb verb)
 {
     if (searcher.Thing.Map.GetComponent <ShieldManager>().Shielded(PositionUtility.ToVector3(searcher.Thing.Position),
                                                                    PositionUtility.ToVector3(target.Thing.Position)))
     {
         return(__result / 2);
     }
     return(__result);
 }
 private static bool IsCellShielded(IntVec3 origin, int cellIndex, Map map, IEnumerable <IShieldField> shields)
 {
     return(new FieldQuery(shields, map)
            .IsActive()
            .Intersects(
                PositionUtility.ToVector3WithY(origin, 0),
                PositionUtility.ToVector3WithY(map.cellIndices.IndexToCell(cellIndex), 0))
            .Get()
            .Any());
 }
Ejemplo n.º 14
0
 private void MakeSequence(FAMMCPosition position, FAPartAction action, FALibrary.Utility.FATime time, string alarmPropertyName)
 {
     PositionUtility obj = new PositionUtility();
     obj.Part = this;
     obj.Position = position;
     obj.PartAction = action;
     obj.Timeout = time;
     obj.AlarmPropertyName = alarmPropertyName;
     obj.Initialize();
 }
Ejemplo n.º 15
0
 private static bool IsShieldedFrom(Map map, IntVec3 cell, Thing threat)
 {
     return(new FieldQuery(map)
            .IsActive()
            .Intersects(
                PositionUtility.ToVector3(threat.Position).Yto0(),
                PositionUtility.ToVector3(cell).Yto0())
            .Get()
            .Any());
 }
Ejemplo n.º 16
0
 // Use this for initialization
 void Start()
 {
     selection   = FindObjectOfType <SelectionController>();
     turn        = FindObjectOfType <TurnManager>();
     turn.isTurn = true;
     tankP1      = FindObjectOfType <PositionTester>();
     utilityP1   = FindObjectOfType <PositionUtility>();
     dealerP1    = FindObjectOfType <PositionDealer>();
     healerP1    = FindObjectOfType <PositionHealer>();
 }
Ejemplo n.º 17
0
    // Fog of war
    void VisitTile(int index)
    {
        // Expanded vision around player
        int column, newX, newY, row = 0;

        PositionUtility.CalculatePosition(index, map.columns, out tmpX, out tmpY);
        // Find halfway point in fov
        var half = Mathf.FloorToInt(distance / 2f);

        // Shift over area to look at tiles around player
        tmpX -= half;
        tmpY -= half;

        var total = distance * distance;
        // Max columns of tiles to visit for reveal tiles
        var maxColumns = distance - 1;

        for (int i = 0; i < total; i++)
        {
            // Current column we're on
            column = i % distance;

            newX = column + tmpX;
            newY = row + tmpY;

            // Recalculate index starting loop on
            PositionUtility.CalculateIndex(newX, newY, map.columns, out index);

            // Make sure index in range
            if (index > -1 && index < map.tiles.Length)
            {
                var tile = map.tiles [index];
                tile.visited = true;
                DecorateTile(index);

                // Update neighbouring tiles
                foreach (var neighbour in tile.neighbours)
                {
                    if (neighbour != null)
                    {
                        if (!neighbour.visited)
                        {
                            neighbour.CalculateFoWAutotileID();
                            DecorateTile(neighbour.id);
                        }
                    }
                }
            }

            if (column == maxColumns)
            {
                row++;
            }
        }
    }
Ejemplo n.º 18
0
    void CenterMap(int index)
    {
        var camPos = Camera.main.transform.position;
        var width  = map.columns;

        PositionUtility.CalculatePosition(index, width, out tmpX, out tmpY);

        camPos.x = tmpX * tileSize.x;
        camPos.y = -tmpY * tileSize.y;
        Camera.main.transform.position = camPos;
    }
Ejemplo n.º 19
0
 private void Start()
 {
     vibrato   = 10;
     strength  = 0.1f;
     tankP1    = FindObjectOfType <PositionTester>();
     tankP2    = FindObjectOfType <PositionTester2>();
     healerP1  = FindObjectOfType <PositionHealer>();
     healerP2  = FindObjectOfType <PositionHealer2>();
     utilityP1 = FindObjectOfType <PositionUtility>();
     utilityP2 = FindObjectOfType <PositionUtility2>();
     dealerP1  = FindObjectOfType <PositionDealer>();
     dealerP2  = FindObjectOfType <PositionDealer2>();
 }
Ejemplo n.º 20
0
        private static bool TryBlock(Thing explosion, DamageDef damType, int damAmount, IntVec3 position)
        {
            if (damType?.defName == null)
            {
                return(false);
            }
            var damages = new ShieldDamages(new ShieldDamage(damType, damAmount));

            return(explosion.Map.GetComponent <ShieldManager>().Block(
                       explosion.TrueCenter(),
                       PositionUtility.ToVector3(position),
                       damages));
        }
Ejemplo n.º 21
0
        protected static bool TryBlock(Map map, Vector3 origin, DamageDef damType, int damAmount, Vector3 position)
        {
            if (damType?.defName == null)
            {
                return(false);
            }
            var damages = new ShieldDamages(new ShieldDamage(damType, damAmount));
            var blocked = new FieldQuery(map)
                          .IsActive()
                          .Intersects(origin, PositionUtility.ToVector3(position).Yto0())
                          .Block(damages);

            return(blocked);
        }
Ejemplo n.º 22
0
    IEnumerator DeedWhiteWalkers()
    {
        while (true)
        {
            int amount = 5 + Random.Range(0, 2);
            amount += currentDeed_.DeedCurrentScore / 5;

            PositionUtility.SpawnDirection dir = PositionUtility.SpawnDirection.TopOrBottom;
            yield return(PositionUtility.SpawnGroup(ActorTypeEnum.LargeWalker, amount, 0.1f, true, dir));

            float delay = 5.0f;
            yield return(new WaitForSeconds(delay));
        }
    }
Ejemplo n.º 23
0
 // Use this for initialization
 void Start()
 {
     selection = FindObjectOfType <SelectionController>();
     utility   = FindObjectOfType <PositionUtility>();
     tankP2    = FindObjectOfType <PositionTester2>();
     healerP2  = FindObjectOfType <PositionHealer2>();
     utilityP2 = FindObjectOfType <PositionUtility2>();
     dealerP2  = FindObjectOfType <PositionDealer2>();
     lm        = FindObjectOfType <LifeManager>();
     turn      = FindObjectOfType <TurnManager>();
     isAttack  = false;
     vibrato   = 10;
     strength  = 0.1f;
 }
 // Use this for initialization
 void Start()
 {
     selection     = FindObjectOfType <SelectionController>();
     healerP1      = FindObjectOfType <PositionHealer>();
     tank          = FindObjectOfType <PositionTester>();
     dealer        = FindObjectOfType <PositionDealer>();
     utility       = FindObjectOfType <PositionUtility>();
     lm            = FindObjectOfType <LifeManager>();
     turn          = FindObjectOfType <TurnManager>();
     isAbility     = false;
     Counter       = 2;
     CounterTurnA  = 0;
     timerAutoHeal = 0f;
 }
Ejemplo n.º 25
0
    // Figure out the next tile to move to, based on direction from key press
    public void MoveInDirection(Vector2 dir)
    {
        PositionUtility.CalculatePosition(currentTile, map.columns, out tmpX, out tmpY);

        // Add direction values to temp x and y
        tmpX += (int)dir.x;
        tmpY += (int)dir.y;

        // Create index of tile to move to
        PositionUtility.CalculateIndex(tmpX, tmpY, map.columns, out tmpIndex);

        // Move player to next tile, with animation
        MoveTo(tmpIndex, true);
    }
Ejemplo n.º 26
0
        private static bool Block(Bullet crashPod, int damage)
        {
            if (crashPod.Map.GetComponent <ShieldManager>().Block(PositionUtility.ToVector3WithY(crashPod.Position, 0), damage))
            {
                Messages.Message("fd.shields.incident.crashpod.blocked.body".Translate(),
                                 new GlobalTargetInfo(crashPod.Position, crashPod.Map), MessageTypeDefOf.NeutralEvent);
                crashPod.def.projectile.soundExplode.PlayOneShot(
                    SoundInfo.InMap(new TargetInfo(crashPod.Position, crashPod.Map)));
                crashPod.Destroy();
                return(true);
            }

            return(false);
        }
Ejemplo n.º 27
0
    IEnumerator BigWalkers()
    {
        while (true)
        {
            int amount = 1 + Random.Range(0, 2);
            amount += SaveGame.RoundScore / 15;

            float delay = SaveGame.RoundScore == 1 ? 5 + Random.value * 3 : 20 + Random.value + amount;
            yield return(new WaitForSeconds(delay));

            bool inside = Random.value < 0.2f;
            PositionUtility.SpawnDirection dir = PositionUtility.GetRandomDirOutside();
            yield return(PositionUtility.SpawnGroup(ActorTypeEnum.LargeWalker, amount, 0.1f, !inside, dir));
        }
    }
Ejemplo n.º 28
0
 private static bool TryBlockOverheadProjectileCE(
     ProjectileCE projectile,
     Vector3 currentPosition,
     int ticksToImpact,
     Vector2 origin)
 {
     return(TryBlock(
                projectile,
                currentPosition,
                ticksToImpact,
                PositionUtility.ToVector3(origin),
                // TODO might be able to calculate the exact path with 3d CE projectiles
                projectile.def.projectile.flyOverhead,
                CalculateDamages(projectile)) != null);
 }
Ejemplo n.º 29
0
        protected static Vector3?TryBlock(
            Thing projectile,
            Vector3 currentPosition,
            Vector3 nextPosition,
            int ticksToImpact,
            Vector3 origin,
            bool flyOverhead,
            ShieldDamages damages)
        {
            var shieldManager = projectile.Map.GetComponent <ShieldManager>();

            if (IsBlacklisted(projectile))
            {
                return(null);
            }

            if (flyOverhead)
            {
                if (ticksToImpact <= 1)
                {
                    // fix for fire foam projectiles having 99999 damage
                    if (projectile.def.defName == "Bullet_Shell_Firefoam")
                    {
                        damages.OverrideDamage = 10;
                    }

                    if (shieldManager.Block(
                            PositionUtility.ToVector3(origin),
                            PositionUtility.ToVector3(currentPosition),
                            // TODO calculate mortar damage better
                            damages))
                    {
                        return(currentPosition);
                    }
                    return(null);
                }
            }
            else
            {
                return(shieldManager.Block(
                           PositionUtility.ToVector3(origin),
                           PositionUtility.ToVector3(currentPosition),
                           PositionUtility.ToVector3(nextPosition),
                           damages));
            }

            return(null);
        }
Ejemplo n.º 30
0
 protected static bool ShieldBlocks(Thing caster, Verb verb, IntVec3 source, LocalTargetInfo target)
 {
     if (Mod.Settings.EnableShootingIn)
     {
         return(false);
     }
     if (!verb.verbProps.requireLineOfSight)
     {
         return(false);
     }
     if (UncheckedTypes.Exists(a => a.IsInstanceOfType(verb)))
     {
         return(false);
     }
     return(caster.Map.GetComponent <ShieldManager>().Shielded(PositionUtility.ToVector3(source), PositionUtility.ToVector3(target.Cell), caster.Faction));
 }
Ejemplo n.º 31
0
 private static bool HandleGeneric(Skyfaller skyfaller)
 {
     try
     {
         if (skyfaller.Map.GetComponent <ShieldManager>().Block(PositionUtility.ToVector3WithY(skyfaller.Position, 0),
                                                                Mod.Settings.SkyfallerDamage))
         {
             skyfaller.def.skyfaller.impactSound?.PlayOneShot(
                 SoundInfo.InMap(new TargetInfo(skyfaller.Position, skyfaller.Map)));
             Messages.Message("fd.shields.incident.skyfaller.blocked.body".Translate(), new GlobalTargetInfo(skyfaller.Position, skyfaller.Map), MessageTypeDefOf.NeutralEvent);
             skyfaller.Destroy();
             return(false);
         }
     }
     catch (InvalidOperationException) {}
     return(true);
 }