Esempio n. 1
0
    public void SetState(BaseUnitState state)
    {
        currentState.Exit();

        currentState = state;
        currentState.Entry();
    }
Esempio n. 2
0
 public MoveToPoint(StateInfo info, Vector2 destination, BaseUnitState nextState)
     : base(info)
 {
     rb               = info.unit.GetComponent <Rigidbody2D>();
     motion           = info.unit.GetComponent <IMotion>();
     _nextState       = nextState;
     this.destination = destination;
 }
Esempio n. 3
0
    private void _shootTarget(BaseUnitState target)
    {
        var shootEvent = new Events.SoldierAttackEvent(State.Id, target.Id, BalanceConsts.SoldierDamage);

        Game.PushEvent(shootEvent);
        State.ShootCooldown = BalanceConsts.SoldierAttackCooldown * _effectiveness;
        State.TargetId      = target.Id;
    }
Esempio n. 4
0
 public void SetState(BaseUnitState newState, BaseUnitState prevState)
 {
     if (prevState != unitState)
     {
         Debug.Assert(false);
     }
     if (unitState != null)
     {
         unitState.DestroyState();
     }
     unitState = newState;
 }
Esempio n. 5
0
    private void _shootTarget(BaseUnitState target)
    {
        var shootEvent = new Events.TurretAttackEvent(State.Id, target.Id, BalanceConsts.TurretDamage);

        Game.PushEvent(shootEvent);

        var pos       = target.Position + M.RadialSpread() * PhysicsConsts.SoldierRadius * 1.5f;
        var explosion = new Events.ExplosionEvent(pos, BalanceConsts.TurretSplashDamage,
                                                  BalanceConsts.TurretSplashRadius, 1.0f, State.LaneKey, State.Side);

        Game.PushEvent(explosion);
        State.ShootCooldown = BalanceConsts.TurretAttackCooldown;
        State.TargetId      = target.Id;
    }
Esempio n. 6
0
    public BaseUnitState GetNearestUnit(BaseUnitState fromUnit, float distance)
    {
        var q = new NearestUnit
        {
            LaneKey     = fromUnit.LaneKey,
            MaxDistance = distance,
            PreferredId = fromUnit.TargetId,
            SearchFrom  = fromUnit.Position
        };

        return(GetNearestUnit(q, unit =>
        {
            return unit.Id != fromUnit.Id &&
            unit.Side != fromUnit.Side &&
            unit.UnitType != UnitType.ControlPoint;
        }));
    }
Esempio n. 7
0
    public void DestroyUnit(bool animation)
    {
        if (unitDestroyed != null)
        {
            unitDestroyed(this);
        }
        unitState = null;
        aimComponent.Deinit();
        Destroy(moralComponent);

        if (animation)
        {
            CreateDeathAnimation();
        }

        DestroyInstance();
        //UnitPool.Instance.ReturnUnitToPool(this);
    }
Esempio n. 8
0
 public void AddState(BaseUnitState state)
 {
     states.Add(state);
 }
Esempio n. 9
0
 // Start is called before the first frame update
 public void Start()
 {
     currentState = new IdleState(new StateInfo(transform, this));
     states       = new List <BaseUnitState>();
 }
Esempio n. 10
0
 public void Initialize(BaseUnitState state)
 {
     currentState = state;
     currentState.Entry();
 }
 public Priest(string name, Vector2 size, float totalHealth, float currentHealth, Vector2 position, BaseUnitState state, TextureValue texture, Color color, TextureValue icon, float range, Stats teamStats) : base(name, size, totalHealth, currentHealth, position, state, texture, color, icon, range, teamStats)
 {
 }
Esempio n. 12
0
 //TODO List of commands needed to be implemented for the units
 public BasicUnit(string name, Vector2 size, float totalHealth, float currentHealth, Vector2 position, BaseUnitState state, TextureValue texture, Color color, TextureValue icon, float range, Stats teamStats) : base(texture, position, teamStats, color)
 {
     Cost      = new Wallet();// TODO charge for units
     this.name = name;
     this.Size = size;
     stats.Add(new Health("Health", totalHealth));
     stats.Add(new Range("Range", range));
     this.CurrentHealth = currentHealth;
     this.UnitState     = state;
     Direction          = new Vector2(0, 0);
     speed     = 0;
     this.Icon = icon;
     aStar     = new A_Star();
     waypoints = new List <Vector2>();
     zero      = Vector2.Zero;
     xOne      = new Vector2(1, 0);
     yOne      = new Vector2(0, 1);
     speed     = 50;
     nextPoint = Position;
     UnitState = BaseUnitState.Idle;
     if (teamStats != null)
     {
         attack = new Melee(stats[typeof(Range)].Value + teamStats[typeof(Range)].Value);
     }
     else
     {
         attack = new Melee(stats[typeof(Range)].Value);
     }
     this.teamStats = teamStats;
 }
Esempio n. 13
0
 //Probably should add a decorator implementation for ranged and melee units this is just more simple at the moment
 public Mage(string name, Vector2 size, float totalHealth, float currentHealth, Vector2 position, BaseUnitState state, TextureValue texture, Color color, TextureValue icon, ProjectileManager projectile, float range, Stats teamStats) : base(name, size, totalHealth, currentHealth, position, state, texture, color, icon, range, teamStats)
 {
     this.projectile = projectile;
     attack          = new Ranged(projectile, TextureValue.FireBall);
     stats.Add(new MeleeDamage("Attack", 5));
     stats.Add(new Health("Health", 10));
 }
 public OffensiveUnits(string name, Vector2 size, float totalHealth, float currentHealth, Vector2 position, BaseUnitState state, TextureValue texture, Color color, TextureValue icon, float range, Stats teamstats) : base(name, size, totalHealth, currentHealth, position, state, texture, color, icon, range, teamstats)
 {
     stats.Add(new MeleeDamage("Attack Power", 10));
 }
 public HostileMob(string name, Vector2 size, float totalHealth, float currentHealth, Vector2 position, BaseUnitState state, TextureValue texture, Color color, TextureValue icon, float range, Stats teamStats) : base(name, size, totalHealth, currentHealth, position, state, texture, color, icon, range, teamStats)
 {
     waypoints = new List <Vector2>();
     speed     = 50;
     stats.Add(new MeleeDamage("Attack", 3));
     tags.Add("CanAttack");
 }
Esempio n. 16
0
 public WaitState(StateInfo info, float time, BaseUnitState nextState)
     : base(info)
 {
     this.time      = time;
     this.nextState = nextState;
 }
Esempio n. 17
0
 public void SetState <T>() where T : BaseUnitState
 {
     currentState.Exit();
     currentState = states.Find((n) => n is T);
 }
Esempio n. 18
0
 public Civilian(string name, Vector2 size, float totalHealth, float currentHealth, Vector2 position, BaseUnitState state, TextureValue texture, TextureValue Icon, float range, ProjectileManager proj, Stats teamStats) : base(name, size, totalHealth, currentHealth, position, state, texture, Color.Blue, Icon, range, teamStats)
 {
     this.proj = proj;
     stats.Add(new BuildPower("Build Power", 10));
     stats.Add(new MeleeDamage("Attack Power", 10));
     stats.Add(new HarvestPower("Harvest Power", 2));
     stats.Add(new InventorySpace("Inventory Space", 10));
     waypoints  = new List <Vector2>();
     zero       = Vector2.Zero;
     xOne       = new Vector2(1, 0);
     yOne       = new Vector2(0, 1);
     toBuild    = new Stack <Building>();
     speed      = 50;
     unitWallet = new UnitWallet(this);
     tags.Add("HasInventoryCap");
     tags.Add("CanAttack");
     tags.Add("HasHealth");
     nextPoint   = TargetPosition = Position;
     Description = "A basic unit able to Harvest resources, and build things\nMinimal Damage";
 }
Esempio n. 19
0
        public Ballista(string name, Vector2 size, float totalHealth, float currentHealth, Vector2 position, BaseUnitState state, TextureValue texture, Color color, TextureValue icon, ProjectileManager projectile, float range, Stats teamStats) : base(name, size, totalHealth, currentHealth, position, state, texture, color, icon, range, teamStats)
        {
            Cost = new Wallet();
            Cost.Deposit(new Steel(), 1);
            Cost.Deposit(new Wood(), 5);
            Cost.Deposit(new Money(), 20);

            attack = new Ranged(projectile, TextureValue.Arrow);

            stats.Add(new MeleeDamage("Attack", 50));
            stats.Add(new Health("Health", 10));
            this.projectile = projectile;
        }
Esempio n. 20
0
 public static void Assign(BaseUnitState state)
 {
     if (state != null)
         stateMap.Add(state.Name, state);
 }