Esempio n. 1
0
    private void ApplyOnSurroundingTiles(IScriptTile origin, int range, Action<IScriptTile, int> action)
    {
      Queue<IScriptTile> queue = new Queue<IScriptTile>();
      List<IScriptTile> passedTiles = new List<IScriptTile>();

      queue.Enqueue(origin);
      queue.Enqueue(null);
      passedTiles.Add(origin);
      action(origin, 0);

      int counter = 0;

      while (queue.Count > 0 && counter < range)
      {
        IScriptTile tile = queue.Dequeue();
        if (tile == null)
        {
          counter++;
          queue.Enqueue(null);
          continue;
        }

        foreach (var d in Misc.FourDirection)
        {
          IScriptTile surrtile = tile.GetSurroundingTile(d);
          if (surrtile != null && !passedTiles.Contains(surrtile))
          {
            passedTiles.Add(surrtile);
            queue.Enqueue(surrtile);
            action(surrtile, counter);
          }
        }
      }
    }
Esempio n. 2
0
    /// <summary>
    /// Creates an animation effect
    /// </summary>
    /// <param id="tile">Tile where the effect will be created</param>
    /// <param id="duration">How long the effect will last</param>
    /// <param id="speed">How fast the animation will go through the frames</param>
    /// <param id="texture">Texture of the animation</param>
    /// <param id="frames">Frames per row in the texture</param>
    /// <param id="rows">Frames per column in the texture</param>
    /// <param id="activeRow">Active row for animation</param>
    /// <param id="overlay">Specifies in which zoneFound the animation should be drawn</param>
    public void CreateAnimationEffect(IScriptTile tile, int duration, int speed, string texture, int frames, int rows, int activeRow, bool overlay)
    {
      Tile tileCasted = (Tile)tile;

      float x = tileCasted.MapPosition.X;
      float y = tileCasted.MapPosition.Y - tileCasted.Elevation * MapBoard.ELEVATION_SCALING;
      Vector2 position = new Vector2(x, y).Round();

      TextureTileSet2D tex = new TextureTileSet2D(UI.Instance.GetTexture(texture), frames, rows);
      tex.SetRow(activeRow);

      GameEffect gEff = new AnimationEffect(tex, position + MapBoard.TILE_SIZE / 2 - tex.FrameSize/2, duration, speed, overlay);
      gEff.Initialize(this, tileCasted);
      this.Effects.Add(gEff);
      SendData(Network.MakeServerMessage(MessageType.GameEffectCreate, gEff));
    }
Esempio n. 3
0
    /// <summary>
    /// Creates a newText scrollup effect
    /// </summary>
    /// <param id="tile">Tile where the effect will be created</param>
    /// <param id="duration">How long the effect will last</param>
    /// <param id="speed">How fast the newText will flow</param>
    /// <param id="newText">Text of the effect</param>
    public void CreateTextScrollUpEffect(IScriptTile tile, int duration, int speed, string text)
    {
      Tile tileCasted = (Tile)tile;

      float x = tileCasted.MapPosition.X;
      float y = tileCasted.MapPosition.Y - tileCasted.Elevation * MapBoard.ELEVATION_SCALING;
      Vector2 position = new Vector2(x, y).Round();

      GameEffect gEff = new ScrollTextEffect(text, position, duration, new Vector2(0, -1) * speed);
      gEff.Initialize(this, tileCasted);
      this.Effects.Add(gEff);
      SendData(Network.MakeServerMessage(MessageType.GameEffectCreate, gEff));
    }
Esempio n. 4
0
 /// <summary>
 /// Creates a resource of given entry at given tile
 /// </summary>
 /// <param id="entry">Db entry of the resource</param>
 /// <param id="tile">Tile if the resource</param>
 /// <returns>The created resource</returns>
 public IScriptResource CreateResource(IScriptDbEntry entry, IScriptTile tile)
 {
   Resource r = new Resource();
   r.Initialize((EntryDb)entry, this, NaturePlayer, (Tile)tile);
   r.InitializeGraphics();
   SendData(Network.MakeServerMessage(MessageType.GameObjCreate, tile));
   return r;
 }
Esempio n. 5
0
 /// <summary>
 /// Creates a building of given entry at given tile with given owner
 /// </summary>
 /// <param id="entry">Db entry of the building</param>
 /// <param id="tile">Tile if the building</param>
 /// <param id="owner">Owner of the building</param>
 /// <returns>The created building</returns>
 public IScriptBuilding CreateBuilding(IScriptDbEntry entry, IScriptTile tile, IScriptPlayer owner)
 {
   Building bldg = new Building();
   bldg.Initialize((EntryDb)entry, this, (Player)owner, (Tile)tile);
   bldg.InitializeGraphics();
   SendData(Network.MakeServerMessage(MessageType.GameObjCreate, bldg));
   return bldg;
 }
Esempio n. 6
0
    /// <summary>
    /// Method that deserializes the data from the line starting at given position in given context depending on the MessageType
    /// </summary>
    /// <param id="mt">MessageType defining the extend of deserialization which is to be performed</param>
    /// <param id="line">String array containing the serialized data</param>
    /// <param id="position">Current position in the array</param>
    /// <param id="context">Context of the serialized data, game where this INetworkSerializable object is in</param>
    public virtual void Deserialize(MessageType mt, string[] line, ref int position, WildmenGame context)
    {
      string entry;
      switch (mt)
      {
        case MessageType.GameTransfer:
        case MessageType.GameEffectCreate:
          entry = line[position++];
          if (entry != Db.NOENTRY) { Entry = Db.Instance.Effects[entry]; }
          else { Entry = null; }
          Speed = int.Parse(line[position++]);
          Duration = int.Parse(line[position++]);
          Time = int.Parse(line[position++]);
          UpdateOffset = ((long.Parse(line[position++]) - UI.Instance.UpdateNumber)) % Speed;
          int tx = int.Parse(line[position++]);
          int ty = int.Parse(line[position++]);
          if (tx == -1 && ty == -1)
            Tile = null;
          else
            Tile = context.Map.Tiles[tx, ty];

          Graphical = line[position++] == "1";
          GraphicalOverlay = line[position++] == "1";

          string target = line[position++];
          if (target != "null") { targetEntity = context.GetGameObjectById(int.Parse(line[position++])); }
          target = line[position++];
          if (target != "null") { targetTile = context.Map.Tiles[int.Parse(target), int.Parse(line[position++])]; }

          int eLocalCount = int.Parse(line[position++]);
          LocalData = new List<object>();
          for (int i = 0; i < eLocalCount; i++)
          {
            target = line[position++];
            if (target == "g") { LocalData.Add(context.GetGameObjectById(int.Parse(line[position++]))); }
            else if (target == "t") { LocalData.Add(context.Map.Tiles[int.Parse(line[position++]), int.Parse(line[position++])]); }
            else { LocalData.Add(line[position++]); }
          }

          break;
        default:
          throw new Exception("GameEffect deserialization error");
      }
    }
Esempio n. 7
0
    //

    /// <summary>
    /// Disposes resources used by this instance
    /// </summary>
    public virtual void Dispose()
    {
      Entry = null;
      game = null;
      LocalData = null;
      targetTile = null;
      targetEntity = null;
    }
Esempio n. 8
0
    /// <summary>
    /// Initialize the GameEffect
    /// </summary>
    /// <param id="game">game this effect belongs to</param>
    /// <param id="tile"></param>
    public virtual void Initialize(WildmenGame game, Tile tile)
    {
      this.game = game;
      this.Tile = tile;

      if (Entry != null)
      {
        if (Entry.Spell.OnSpellStartGameEntity != null && Entry.Spell.Target == SpellEntry.TargetType.GameEntity)
        {
          Entry.Spell.OnSpellStartGameEntity(game, this, caster, targetEntity);
        }
        else if (Entry.Spell.OnSpellStartTile != null && Entry.Spell.Target == SpellEntry.TargetType.Tile)
        {
          Entry.Spell.OnSpellStartTile(game, this, caster, targetTile);
        }
      }

      targetEntity = null;
      targetTile = null;

      UpdateOffset = -UI.Instance.UpdateNumber % Speed;
      UpdateOffset++;

    }
Esempio n. 9
0
 /// <summary>
 /// Constructor for scripted GameEffect
 /// </summary>
 /// <param id="effect">The effect database entry</param>
 /// <param id="caster">The caster of the spell</param>
 /// <param id="target">Target tile for the effect</param>
 public GameEffect(EffectDb effect, IScriptUnit caster, IScriptTile target)
 {
   this.targetTile = target;
   this.Entry = effect;
   this.caster = caster;
   LocalData = new List<object>();
   Active = true;
   Time = 0;
   Graphical = false;
   GraphicalOverlay = false;
 }
Esempio n. 10
0
    /// <summary>
    /// Sets new tile for this building
    /// </summary>
    /// <param id="newTile">New tile this building will be move to</param>
    public void SetNearestTile(IScriptTile newTile)
    {
      if (Health == 0) return;
      if (newTile == null) return;
      if (newTile == NearestTile) return;

      foreach (var tile in claimedTiles)
      {
        tile.Unassign(this);
      }
      ClaimTiles((Tile)newTile);

      RecalculatePosition = true;
    }
Esempio n. 11
0
 public int GetDistanceTo(IScriptTile t) => GetDistanceTo((Tile)t);
Esempio n. 12
0
    /// <summary>
    /// Sets new tile for this resource
    /// </summary>
    /// <param id="newTile">New tile this resource will be move to</param>
    public void SetNearestTile(IScriptTile newTile)
    {
      NearestTile.Unassign(this);
      Tile newTileCasted = (Tile)newTile;
      newTileCasted.Assign(this);
      NearestTile = newTileCasted;

      RecalculatePosition = true;

      game.SendData(Network.MakeServerMessage(MessageType.GameObjUpdate, this));
    }
Esempio n. 13
0
 /// <summary>
 /// Sets fog of war visibility for given tile
 /// </summary>
 /// <param id="tile">Tile we want to set the fog of war visibility value to</param>
 /// <param id="newFow">New fog of war value</param>
 public void SetFowVisibility(IScriptTile tile, byte newFow)
 {
   if (newFow > 2) newFow = 2;
   Fow[tile.GetX(), tile.GetY()] = newFow;
 }
Esempio n. 14
0
 /// <summary>
 /// Gets fog of war visibility for given tile
 /// </summary>
 /// <param id="tile">Tile we want to get the fog of war visibility value from</param>
 /// <returns>Fog of war visibility value</returns>
 public byte GetFowVisibility(IScriptTile tile)
 {
   return Fow[tile.GetX(), tile.GetY()];
 }