Exemplo n.º 1
0
 /// <summary>
 /// Initializes a resource using tile as position
 /// </summary>
 /// <param id="entry">Entry defining the type of this game object</param>
 /// <param id="game">Game this game object is in</param>
 /// <param id="player">Owner of this game object</param>
 /// <param id="mapTiles">Tile where this game object is placed</param>
 public override void Initialize(EntryDb entry, WildmenGame game, Player player, Tile mapTile)
 {
   AssignUID(game);
   this.entry = (ResourceDb)entry;
   this.Amount = this.entry.InitialAmount;
   this.game = game;
   this.Owner = player;
   player.Assign(this);
   this.NearestTile = mapTile;
   this.MapPosition = mapTile.MapPosition;
   this.RecalculatePosition = true;
 }
Exemplo n.º 2
0
    /// <summary>
    /// Gives unit an order with specified parameters
    /// </summary>
    /// <param id="order">New game object order</param>
    /// <param id="orderParam">Order's EntryDb parameter</param>
    /// <param id="targetTile">Tracked tile at the moment of giving order</param>
    /// <param id="targetGameObject">Tracked game object at the moment of giving order</param>
    /// <returns>Returns true if the order was successfully applied to the game object</returns>
    public override bool SetOrder(GameObjectOrder order, EntryDb orderParam, Tile targetTile, GameObject targetGameObject)
    {
      if (this.game.IsServer) Debug.Fail("Server isn't supposed to call this routine");

      if (!base.SetOrder(order, orderParam, targetTile, targetGameObject))
      {
        game.SendData(Network.MakeClientMessage(MessageType.GameObjUpdate, this));
        return false;
      }

      if (!CanDoOrder(order))
      {
        GameEffect ge = new ScrollTextEffect("Unit cannot attack", Position, 50, new Vector2(0, -1f));
        ge.Initialize(game, NearestTile);
        this.game.Effects.Add(ge);

        CancelOrders(true);
        return false;
      }

      BuildingDb bldgEntry;

      switch (order)
      {
        case GameObjectOrder.Idle:
          #region
          if (targetTile == null) return false;
          OrderTarget = null;
          OrderRange = MOVEMENT_RANGE;
          OrderPosition = targetTile.MapPosition + new Vector2(MapBoard.TILE_XSPACING, MapBoard.TILE_YSPACING) / 2;
          #endregion
          break;
        case GameObjectOrder.Attack:
          #region
          if (targetGameObject == null) return false; // Hit something
          if (targetGameObject == this) return false; // Don't hit yourself
          OrderTarget = targetGameObject;
          OrderRange = entry.AttackRange;
          OrderTimeout = entry.AttackSpeed;
          #endregion
          break;
        case GameObjectOrder.Construct:
          #region
          OrderRange = entry.ConstructRange;
          OrderTimeout = entry.ConstructSpeed;

          if (targetGameObject != null && targetGameObject.GetEntityType == GameEntityType.Building)
          {
            OrderTarget = targetGameObject;
            OrderEntry = null;
          }
          else if (targetGameObject == null || targetGameObject.GetEntityType == GameEntityType.Unit)
          {
            if (orderParam == null) return false;
            bldgEntry = (BuildingDb)orderParam;
            if (bldgEntry.OnlyOneAllowed && Owner.Buildings.Any(q => q.Entry == orderParam))
            {
              ScrollUpMessage("Only one such building allowed at a time", 50, false);
              CancelOrders(true);
              return false;
            }
            if (bldgEntry.UnlockedBy != null)
            {
              Building bldg = Owner.Buildings.FirstOrDefault(q => q.Entry == bldgEntry.UnlockedBy);
              if (bldg == null || !bldg.Constructed)
              {
                ScrollUpMessage("Building unavailable", 100, true);
                CancelOrders(true);
                return false;
              }
            }

            OrderTarget = null;
            OrderEntry = (BuildingDb)orderParam;
            OrderPosition = targetTile.MapPosition + new Vector2(MapBoard.TILE_XSPACING, MapBoard.TILE_YSPACING) / 2;
          }
          #endregion
          break;
        case GameObjectOrder.Spell:
          #region

          EffectDb effect = (EffectDb)orderParam;

          if (effect.UnlockedBy != null)
          {
            Building bldg = Owner.Buildings.FirstOrDefault(q => q.Entry == effect.UnlockedBy);
            if (bldg == null || !bldg.Constructed)
            {
              ScrollUpMessage("Spell unavailable", 100, true);
              CancelOrders(true);
              return false;
            }
          }

          OrderEntry = effect;
          OrderRange = effect.CastRange;
          OrderTimeout = effect.Cooldown;
          switch (effect.Spell.Target)
          {
            case SpellEntry.TargetType.Tile:
              if (targetTile == null) return false;
              OrderRange = effect.CastRange;
              OrderPosition = targetTile.MapPosition + new Vector2(MapBoard.TILE_XSPACING, MapBoard.TILE_YSPACING) / 2;
              break;
            case SpellEntry.TargetType.GameEntity:
              if (targetGameObject == null) return false;
              OrderTarget = targetGameObject;
              break;
          }
          #endregion
          break;
        case GameObjectOrder.Gather:
          #region
          if (targetGameObject == null) return false;
          OrderTarget = targetGameObject;
          if (targetGameObject.GetEntityType == GameEntityType.Resource)
          {
            lastGatheredResource = (Resource)targetGameObject;
          }
          else if (targetTile != null && targetTile.Resource != null)
          {
            lastGatheredResource = targetTile.Resource;
          }
          else
          {
            CancelOrders(true);
            return false;
          }
          OrderRange = entry.GatherRange;
          OrderTimeout = entry.GatherSpeed;
          #endregion
          break;
        case GameObjectOrder.Train:
          #region
          if (targetGameObject == null) return false;
          if (targetGameObject.GetEntityType != GameEntityType.Building) return false;
          bldgEntry = (BuildingDb)((Building)targetGameObject).Entry;
          if (bldgEntry.Trains == null) return false;
          if (bldgEntry.Trains.All(p=>p.TrainFrom != this.Entry)) return false;

          OrderTarget = targetGameObject;
          OrderRange = MOVEMENT_RANGE;
          OrderTimeout = TRAIN_QUEUE_CHECK_TIMEOUT;
          #endregion
          break;
        default:
          break;
      }
      State = GameObjectState.MovingToOrder;
      this.Order = order;
      game.SendData(Network.MakeClientMessage(MessageType.GameObjUpdate, this));
      return true;
    }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes this unit
 /// </summary>
 /// <param id="entry">Entry defining the type of this game object</param>
 /// <param id="game">Game this game object is in</param>
 /// <param id="player">Owner of this game object</param>
 /// <param id="mapPosition">Vector where this game object is placed</param>
 public override void Initialize(EntryDb entry, WildmenGame game, Player player, Vector2 mapPosition)
 {
   AssignUID(game);
   Logger.Log(string.Format("Unit #{0} initialized", this.ObjectUID), "Server update");
   player.Assign(this);
   this.State = GameObjectState.Idle;
   this.Order = GameObjectOrder.Idle;
   this.game = game;
   this.Owner = player;
   this.entry = ((UnitDb)entry).Clone();
   this.MapPosition = mapPosition;
   this.RecalculatePosition = true;
   this.IsMovable = true;
   this.Health = this.entry.Health;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a game object using vector as position
 /// </summary>
 /// <param id="entry">Entry defining the type of this game object</param>
 /// <param id="game">Game this game object is in</param>
 /// <param id="player">Owner of this game object</param>
 /// <param id="mapPosition">Vector where this game object is placed</param>
 public abstract void Initialize(EntryDb entry, WildmenGame game, Player player, Vector2 mapPosition);
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a game object using tile as position
 /// </summary>
 /// <param id="entry">Entry defining the type of this game object</param>
 /// <param id="game">Game this game object is in</param>
 /// <param id="player">Owner of this game object</param>
 /// <param id="mapTiles">Tile where this game object is placed</param>
 public abstract void Initialize(EntryDb entry, WildmenGame game, Player player, Tile mapTiles);
Exemplo n.º 6
0
 /// <summary>
 /// Gives unit an order with specified parameters
 /// </summary>
 /// <param id="order">New game object order</param>
 /// <param id="orderParam">Order's EntryDb parameter</param>
 /// <param id="targetTile">Tracked tile at the moment of giving order</param>
 /// <param id="targetGameObject">Tracked game object at the moment of giving order</param>
 /// <returns>Returns true if the order was successfully applied to the game object</returns>
 public virtual bool SetOrder(GameObjectOrder order, EntryDb orderParam, Tile targetTile, GameObject targetGameObject)
 {
   if (Health == 0) return false;
   CancelOrders();
   if (targetTile == null && targetGameObject == null) return false;
   if (!CanDoOrder(order)) return false;
   return true;
 }
Exemplo n.º 7
0
    /// <summary>
    /// Initializes this instance and claims the tiles
    /// </summary>
    /// <param name="entry">Type of this building</param>
    /// <param name="game">The game this building is in</param>
    /// <param name="player">The owner of this building</param>
    /// <param name="baseTile">The base tile determining the position of this building</param>
    public override void Initialize(EntryDb entry, WildmenGame game, Player player, Tile baseTile)
    {
      AssignUID(game);
      Logger.Log(string.Format("Building #{0} initialized", this.ObjectUID), "Server update");
      player.Assign(this);
      this.game = game;
      this.Owner = player;
      this.entry = (BuildingDb)entry;
      this.NearestTile = baseTile;
      ClaimTiles(baseTile);
      this.MapPosition = baseTile.MapPosition;
      this.RecalculatePosition = true;

      this.Health = this.entry.Health;
      this.Construction = 0;

      if (Construction >= this.entry.ConstructionAmount)
      {
        Completed(false);
      }
    }