Beispiel #1
0
    public override Speech GetSpeech()
    {
        if (M_Math.Roll(Chance))
        {
            return(M_Weightable.GetWeighted(Speeches));
        }


        return(null);
    }
Beispiel #2
0
    public virtual Speech GetSpeech(string trigger)
    {
        SpeechTriggerConfigIDGroupConfig _speech = Groups.FirstOrDefault(gr => gr.ID == trigger);

        if (_speech != null && M_Math.Roll(_speech.Chance))
        {
            return(M_Weightable.GetWeighted(_speech.Speeches));
        }

        return(null);
    }
Beispiel #3
0
    void OnDmgReceived(UnitEffect_Damage dmg)
    {
        if (dmg.Instigator == null)
        {
            return;
        }

        if (!_triggered)
        {
            MDebug.Log(dmg.Instigator.ToString());
            Trigger(dmg.Instigator as Unit);
        }
        else
        {
            if (M_Math.Roll(Constants.GetAggroChance(m_unit, dmg)))
            {
                SetPreferredTarget((dmg.Instigator as Unit));
            }
        }
    }
Beispiel #4
0
    void Count()
    {
        count++;
        if (count == 10)
        {
            TrackingManager.TrackingCall_EasterEgg("10", PlayerLevel.Instance.GetCurrentLevel());
            WaypointMover          mover = gameObject.AddComponent <WaypointMover>();
            UnitRotationController contr = gameObject.AddComponent <UnitRotationController>().Init(mover, _foo);
            contr.TurnToPosition(Camera.main.transform, () => m_animation.SetTrigger(UnitAnimationTypes.bAggro.ToString()));
        }
        else if (count == 20)
        {
            TrackingManager.TrackingCall_EasterEgg("20", PlayerLevel.Instance.GetCurrentLevel());
            m_animation.SetTrigger(UnitAnimationTypes.bDying.ToString());
        }
        else if (count == 3 || (count > 3 && M_Math.Roll(0.1f)))
        {
            TrackingManager.TrackingCall_EasterEgg("3", PlayerLevel.Instance.GetCurrentLevel());

            m_animation.SetTrigger(UnitAnimationTypes.bHit.ToString());
        }
    }
Beispiel #5
0
    IEnumerator Decide()
    {
        if (!m_Actions.HasAP(1))
        {
            yield return(null);
        }

        if (_triggered)
        {
            yield return(StartCoroutine(AttackOrMove()));
        }
        else if (m_Actions.HasAP(2) && M_Math.Roll(Constants.AI_PATROL_CHANCE) && m_unit.Stats.GetStatAmount(StatType.move_range) > 0)
        {
            MDebug.Log("^aiPATROL");
            yield return(StartCoroutine(MovePatrol()));
        }
        else
        {
            yield return(new WaitForSeconds(1f));

            SkipTurn();
            yield return(null);
        }
    }
Beispiel #6
0
    IEnumerator AttackOrMove()
    {
        MDebug.Log("What to do..`?");

        UnitAction_ApplyEffectFromWeapon attack = getAttack();
        UnitAction_Move move = getMove();

        //dictionary of all units and the paths by which they are attackable
        Dictionary <Unit, List <List <Tile> > > attack_map = GetPathMapForTargets();

        MDebug.Log("^aiAttack Map Count:" + attack_map.Count);
        List <Unit> units_attackable = Unit.GetAllUnitsOfOwner(0, false).Where(unit => attack.CanTarget(unit)).ToList();

        MDebug.Log("^aiAttackable " + units_attackable.Count);
        List <Unit> units_move_attackable = attack_map.Where(kvp => CanFinishPathInMoves(1, kvp.Value)).Select(kvp => kvp.Key).ToList();
        List <Unit> units_movable         = attack_map.Where(kvp => !units_move_attackable.Contains(kvp.Key)).Select(kvp => kvp.Key).ToList();


        if (attack_map.Count > 0 && (preferred_target == null || !preferred_target.IsActive))
        {
            preferred_target = M_Math.GetRandomObject(attack_map.Select(kvp => kvp.Key).ToList());
        }

        if (preferred_target == null)
        {
            yield return(StartCoroutine(MoveRandom()));

            yield break;
        }

        if (!units_attackable.Contains(preferred_target) && (!units_attackable.IsNullOrEmpty() && (!attack_map.ContainsKey(preferred_target) || M_Math.Roll(Constants.AI_TARGET_SWITCH_WHEN_OUT_OF_ATTACK_RANGE))))
        {
            MDebug.Log("^ainew Prefferred  from" + units_attackable.Count);
            preferred_target = M_Math.GetRandomObject(units_attackable);
        }

        if (attack.CanTarget(preferred_target) && units_attackable.Contains(preferred_target))
        {
            Tile better_pos = GetReachableAttackPosition(preferred_target);

            if (m_Actions.HasAP(2) && better_pos != null)
            {
                yield return(StartCoroutine(Move(better_pos)));

                yield break;
            }
            else
            {
                yield return(StartCoroutine(Attack(preferred_target)));

                yield break;
            }
        }
        else
        {
            List <Unit> other_move_targets = units_move_attackable.Where(unit => unit != preferred_target && !units_attackable.Contains(unit)).ToList();

            if (!other_move_targets.IsNullOrEmpty() && M_Math.Roll(Constants.AI_TARGET_SWITCH_TO_ATTACK_MOVE_WHEN_OUT_OF_MOVE_ATTACK_RANGE))
            {
                preferred_target = M_Math.GetRandomObject(other_move_targets);
            }
            else
            {
                if (!attack_map.ContainsKey(preferred_target) && !units_movable.IsNullOrEmpty() && M_Math.Roll(Constants.AI_TARGET_SWITCH_TO_CHASE_WHEN_OUT_OF_ATTACK_RANGE))
                {
                    preferred_target = M_Math.GetRandomObject(units_movable);
                }
            }

            if (attack_map.ContainsKey(preferred_target))
            {
                if (units_move_attackable.Contains(preferred_target))
                {
                    Tile attack_pos = GetReachableAttackPosition(preferred_target);

                    if (attack_pos != null)
                    {
                        yield return(StartCoroutine(Move(attack_pos)));
                    }
                    else
                    {
                        yield return(StartCoroutine(MoveRandom()));
                    }

                    yield break;
                }
                else
                {
                    Tile Final_Target_Tile = GetBestAttackPosition(preferred_target, attack_map[preferred_target].Select(path => path[path.Count - 1]).ToList());

                    List <Tile> final_path = TileManager.Instance.FindPath(m_unit.currentTile, Final_Target_Tile, m_unit);

                    Tile target = move.GetFurthestMovibleTileOnPath(final_path);

                    yield return(StartCoroutine(Move(target)));

                    yield break;
                }
            }
            else
            {
                yield return(StartCoroutine(MoveRandom( )));

                yield break;
            }
        }
    }