コード例 #1
0
ファイル: Building.cs プロジェクト: arcticnw/Wildmen
 /// <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 override void Deserialize(MessageType mt, string[] line, ref int position, WildmenGame context)
 {
   base.Deserialize(mt, line, ref position, context);
   switch (mt)
   {
     case MessageType.GameTransfer:
     case MessageType.GameObjCreate:
       entry = Db.Instance.Buildings[line[position++]];
       Construction = int.Parse(line[position++]);
       break;
     case MessageType.GameObjUpdate:
       Construction = int.Parse(line[position++]);
       break;
     case MessageType.GameObjEntryUpdate:
       entry = Db.Instance.Buildings[line[position++]];
       break;
     case MessageType.GameObjKill:
       break;
     default:
       throw new Exception("Building deserialization error");
   }
 }
コード例 #2
0
ファイル: BuildingDb.cs プロジェクト: arcticnw/Wildmen
    /// <summary>
    /// Loads building entries from provided file into provided dictionary
    /// </summary>
    /// <param id="dict">Dictionary the entries will be loaded into</param>
    /// <param id="xmlFile">File the entries are loaded from</param>
    public static void LoadBuildings(SortedDictionary<string, BuildingDb> dict, XDocument xmlFile)
    {
      var bldgEntries = xmlFile.Descendants("Building");
      foreach (var bldgXml in bldgEntries)
      {
        BuildingDb bldgEntry = new BuildingDb();
        List<CostEntry> costEntries;

        foreach (XNode en in bldgXml.Nodes())
        {
          XElement e = en as XElement;
          if (e == null) continue;
          switch (e.Name.LocalName.ToLower())
          {
            case "id": bldgEntry.Id = e.Value; break;
            case "name": bldgEntry.Name = e.Value; break;
            case "tier": bldgEntry.Tier = int.Parse(e.Value); break;
            case "health": bldgEntry.Health = int.Parse(e.Value); break;
            case "constructiontime": bldgEntry.ConstructionAmount = int.Parse(e.Value); break;
            case "texture":
              if (!UI.Instance.HaveTexture(e.Value))
              {
                throw new Exception("Entry: " + bldgEntry.Id + " - texture " + e.Value + " not found");
              }
              bldgEntry.Texture = UI.Instance.GetTexture(e.Value);
              break;
            case "textureconstruction":
              if (!UI.Instance.HaveTexture(e.Value))
              {
                throw new Exception("Entry: " + bldgEntry.Id + " - texture " + e.Value + " not found");
              }
              bldgEntry.TextureConstruction = UI.Instance.GetTexture(e.Value);
              break;
            case "resourcecenter": bldgEntry.ResourceCenter = bool.Parse(e.Value); break;
            case "onlyoneallowed": bldgEntry.OnlyOneAllowed = bool.Parse(e.Value); break;
            case "builtonstart": bldgEntry.BuiltOnStart = bool.Parse(e.Value); break;
            case "unlockedby": bldgEntry.UnlockedByUR = e.Value; break;
            case "costs":
              #region
              costEntries = new List<CostEntry>();
              foreach (XNode eCostsn in e.Nodes())
              {
                XElement eCosts = eCostsn as XElement;
                if (eCosts == null) continue;

                CostEntry costEntry = new CostEntry();
                foreach (XNode een in eCosts.Nodes())
                {
                  XElement ee = een as XElement;
                  if (ee == null) continue;

                  switch (ee.Name.LocalName.ToLower())
                  {
                    case "resource": costEntry.EntryUR = ee.Value; break;
                    case "amount": costEntry.Amount = int.Parse(ee.Value); break;
                  }
                }
                costEntries.Add(costEntry);
              }
              bldgEntry.Cost = costEntries.ToArray();
              #endregion
              break;
            case "trains":
              #region
              var trainEntries = new List<TrainEntry>();
              foreach (XNode eTrainn in e.Nodes())
              {
                XElement eTrain = eTrainn as XElement;
                if (eTrain == null) continue;

                TrainEntry trainEntry = new TrainEntry();
                foreach (XNode een in eTrain.Nodes())
                {
                  XElement ee = een as XElement;
                  if (ee == null) continue;

                  switch (ee.Name.LocalName.ToLower())
                  {
                    case "from": trainEntry.TrainFromUR = ee.Value; break;
                    case "to": trainEntry.TrainToUR = ee.Value; break;
                    case "speed": trainEntry.Speed = int.Parse(ee.Value); break;
                    case "costs":
                      costEntries = new List<CostEntry>();
                      foreach (XNode eCostsn in ee.Nodes())
                      {
                        XElement eCosts = eCostsn as XElement;
                        if (eCosts == null) continue;

                        CostEntry costEntry = new CostEntry();
                        foreach (XNode eeen in eCosts.Nodes())
                        {
                          XElement eee = eeen as XElement;
                          if (eee == null) continue;

                          switch (eee.Name.LocalName.ToLower())
                          {
                            case "resource": costEntry.EntryUR = eee.Value; break;
                            case "amount": costEntry.Amount = int.Parse(eee.Value); break;
                          }
                        }
                        costEntries.Add(costEntry);
                      }
                      trainEntry.Cost = costEntries.ToArray();
                      break;
                  }
                }
                trainEntries.Add(trainEntry);
              }
              bldgEntry.Trains = trainEntries.ToArray();
              #endregion
              break;
            case "spawns":
              #region
              List<BuildingDb.SpawnEntry> spawnEntries = new List<BuildingDb.SpawnEntry>();
              foreach (XNode eSpawnsn in e.Nodes())
              {
                XElement eSpawns = eSpawnsn as XElement;
                if (eSpawns == null) continue;

                BuildingDb.SpawnEntry spawnEntry = new BuildingDb.SpawnEntry();
                foreach (XNode een in eSpawns.Nodes())
                {
                  XElement ee = een as XElement;
                  if (ee == null) continue;

                  switch (ee.Name.LocalName.ToLower())
                  {
                    case "entry": spawnEntry.EntryUR = ee.Value; break;
                    case "speed": spawnEntry.Speed = int.Parse(ee.Value); break;
                    case "capacity": spawnEntry.Capacity = int.Parse(ee.Value); break;
                  }
                }
                spawnEntries.Add(spawnEntry);
              }
              bldgEntry.Spawns = spawnEntries.ToArray();
              #endregion
              break;
          }
        }
        dict.Add(bldgEntry.Id, bldgEntry);
      }
    }
コード例 #3
0
ファイル: Building.cs プロジェクト: arcticnw/Wildmen
 /// <summary>
 /// Sets the DbEntry for this building
 /// </summary>
 /// <param id="newEntry">New DbEntry for this building</param>
 public void SetDbEntry(IScriptDbEntry newEntry)
 {
   BuildingDb newEntryCast = newEntry as BuildingDb;
   if (newEntryCast == null) return;
   entry = newEntryCast;
   game.SendData(Network.MakeServerMessage(MessageType.GameObjEntryUpdate, this));
 }
コード例 #4
0
ファイル: Building.cs プロジェクト: arcticnw/Wildmen
    // 

    /// <summary>
    /// Disposes resources used by this instance
    /// </summary>
    public override void Dispose()
    {
      entry = null;
      FurtestTile = null;
      Owner.Unassign(this);
      foreach (var item in claimedTiles)
      {
        item.Unassign(this);
      }
      claimedTiles.Clear();
      base.Dispose();
    }
コード例 #5
0
ファイル: Building.cs プロジェクト: arcticnw/Wildmen
    /// <summary>
    /// Draws a building of given type at given tile
    /// </summary>
    /// <param name="offset">Screen offset</param>
    /// <param name="tile">Tile, where the building should be drawn</param>
    /// <param name="highlight">Highlight mode</param>
    /// <param name="entry">Type of the building</param>
    public static void Draw(Vector2 offset, Tile tile, GameObjectHighlightMode highlight, BuildingDb entry)
    {
      float x = tile.MapPosition.X;
      int height = tile.Elevation;
      float y = tile.MapPosition.Y - height * MapBoard.ELEVATION_SCALING;
      Vector2 position = new Vector2(x, y).Round();
      Vector2 textureSize = entry.Texture.Size();
      float aOffX = textureSize.X / 2 - MapBoard.TILE_XSPACING / 2;
      float aOffY = textureSize.Y - MapBoard.TILE_YSPACING;
      Vector2 alignmentOffset = new Vector2(-aOffX, -aOffY);
      Vector2 drawPosition = position - offset + alignmentOffset;

      Color c = Color.Lerp(Color.White, Color.Transparent, .5f);
      if (highlight == GameObjectHighlightMode.InvalidPlacement)
        c = Color.Lerp(c, Color.Red, .5f);

      UI.Instance.Draw(drawPosition, entry.Texture, c, 1f);
    }
コード例 #6
0
ファイル: Building.cs プロジェクト: arcticnw/Wildmen
    /// <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);
      }
    }
コード例 #7
0
ファイル: MapUI.cs プロジェクト: arcticnw/Wildmen
    /// <summary>
    /// Gets training hint for given building entry
    /// </summary>
    /// <param id="bldgEntry">Building entry to get hint for</param>
    /// <returns>String containing hint for the building entry's training information</returns>
    private string GetTrainingHint(BuildingDb bldgEntry)
    {
      string text = "";
      if (bldgEntry.Trains != null)
      {
        foreach (var trainEntry in bldgEntry.Trains)
        {
          if (trainEntry.TrainFrom == selectedObjects[0].Entry)
            text = "Train:\n" + trainEntry.TrainTo.Name;
          else
            text = "(Train)\n" + trainEntry.TrainTo.Name + " (" + trainEntry.TrainFrom.Name + " required)";

          text += "\nRequires: ";
          bool first = true;
          if (trainEntry.Cost != null)
          {
            foreach (var cost in trainEntry.Cost)
            {
              if (!first) text += "; "; else first = false;
              text += cost.Entry.Name + ": " + cost.Amount;
            }
          }
          if (first) text += "no resources";
          text += "\n";
        }
      }
      return text;
    }