Ejemplo n.º 1
0
    public void RemoveUnit(Unit unit)
    {
        _units.Remove(unit);
        _auto -= unit.unregisterFatalWounds(OnUnitDied);

        fire(Actions.UNIT_REMOVED, unit);
    }
Ejemplo n.º 2
0
    public void AddUnit(Unit unit)
    {
        if (!_units.Contains(unit))
        {
            _units.Add(unit);
            _auto += unit.registerFatalWounds(OnUnitDied);

            fire(Actions.UNIT_ADDED, unit);
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Object initialization
    /// </summary>
    public override void Awake()
    {
        _info = Info.get.of(race, type);
        _auto = this;
        Troop = null;

        // Call GameEntity awake
        base.Awake();

        // Get DetourAgent and set basic variables
        _detourAgent = GetComponent <DetourAgent>();
    }
Ejemplo n.º 4
0
    //used for AI so smellEnemies is always true
    public Squad(Storage.Races race, int error)
    {
        _auto = new AutoUnregister(this);
        _race = race;

        _data.Add(DataType.BOUNDING_BOX, new BoundingBox(this));
        _data.Add(DataType.ATTACK_VALUE, new AttackValue(this, error));
        _data.Add(DataType.PATROL_DATA, new PatrolData(this));
        _data.Add(DataType.ASSIST_DATA, new AssistData(this));

        _maxAttackRange = Storage.Info.get.of(_race, Storage.UnitTypes.THROWN).unitAttributes.rangedAttackFurthest;
        _data.Add(DataType.SMELLED_ENEMIES, new SmelledEnemies(this));
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Sets up our attack target, registers callback for its death and
    /// updates our state.
    /// If target is in range, attaks it, otherwise starts moving towards it.
    /// </summary>
    /// <param name="unit"></param>
    /// <returns>Returns true if target is in range, false otherwise</returns>
    public bool attackTarget <A>(GameEntity <A> entity, bool selfDefense) where A : struct, IConvertible
    {
        // HACK: Ideally, we should not have to consider an special case for WatchTower / LightHouse Revealer
        if (entity.info.isPseudoUnit)
        {
            Barrack barrack = entity.transform.GetComponentInParent <Barrack>();
            if (barrack.status != EntityStatus.DESTROYED)
            {
                return(attackTarget(barrack, selfDefense));
            }

            return(false);
        }

        // Note: Cast is redundant but avoids warning
        if (_target != (IGameEntity)entity)
        {
            // Stop attacking current target
            Selectable selectable = null;
            if (status == EntityStatus.ATTACKING)
            {
                selectable = _target.getGameObject().GetComponent <Selectable>();
                selectable.NotAttackedEntity();
                stopAttack();
            }

            // Register for DEAD/DESTROYED and HIDDEN
            _auto += entity.registerFatalWounds(onTargetDied);
            _auto += entity.GetComponent <FOWEntity>().register(FOWEntity.Actions.HIDDEN, onTargetHidden);

            _target      = entity;
            _selfDefense = selfDefense;
            _lastAttack  = Time.time - (1f / info.unitAttributes.attackRate);

            // Show target health
            selectable = _target.getGameObject().GetComponent <Selectable>();
            selectable.AttackedEntity();

            // Update distance for immediate usage (ie. canDoRangedAttack)
            updateDistanceToTarget();

            // Update status and return
            setStatus(EntityStatus.ATTACKING);
            return(true);
        }

        // TODO: Hack to get AI working
        return(true);
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Stops attacking the target and goes back to an IDLE state
    /// </summary>
    public void stopAttack()
    {
        if (_target != null)
        {
            // Hide target health
            Selectable selectable = _target.getGameObject().GetComponent <Selectable>();
            selectable.NotAttackedEntity();

            // Unregister all events
            _auto  -= _target.unregisterFatalWounds(onTargetDied);
            _auto  -= _target.getGameObject().GetComponent <FOWEntity>().unregister(FOWEntity.Actions.HIDDEN, onTargetHidden);
            _target = null;

            setStatus(EntityStatus.IDLE);
        }
    }
Ejemplo n.º 7
0
    public Squad(Storage.Races race, bool smellEnemies = true)
    {
        _auto = new AutoUnregister(this);
        _race = race;

        _data.Add(DataType.BOUNDING_BOX, new BoundingBox(this));
        _data.Add(DataType.ATTACK_VALUE, new AttackValue(this));
        _data.Add(DataType.PATROL_DATA, new PatrolData(this));
        _data.Add(DataType.ASSIST_DATA, new AssistData(this));

        // Smelled squads can not smell enemies or we would run into endless recursion
        if (smellEnemies)
        {
            _maxAttackRange = Storage.Info.get.of(_race, Storage.UnitTypes.THROWN).unitAttributes.rangedAttackFurthest;
            _data.Add(DataType.SMELLED_ENEMIES, new SmelledEnemies(this));
        }
        else
        {
            _maxAttackRange = 1f;
        }
    }
Ejemplo n.º 8
0
 public SquadData(Squad squad)
 {
     auto  = new AutoUnregister(this);
     auto += squad.register(Squad.Actions.UNIT_ADDED, OnAdded);
     auto += squad.register(Squad.Actions.UNIT_REMOVED, OnRemoved);
 }