Пример #1
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;
 }
Пример #2
0
    // MISC

    /// <summary>
    /// Disposes resources used by this instance
    /// </summary>
    public override void Dispose()
    {
      entry = null;
      Owner.Unassign(this);
      if (NearestTile != null)
      {
        NearestTile.Unassign(this);
      }
      OrderTarget = null;
      this.ResetCache();
      base.Dispose();
    }
Пример #3
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 override void Deserialize(MessageType mt, string[] line, ref int position, WildmenGame context)
 {
   base.Deserialize(mt, line, ref position, context);
   long lastGatheredResId;
   string carryTypeId;
   switch (mt)
   {
     case MessageType.GameTransfer:
     case MessageType.GameObjCreate:
       // Entry
       entry = Db.Instance.Units[line[position++]].Clone();
       entry.Deserialize(mt, line, ref position, context);
       // Last gathered resource
       lastGatheredResId = long.Parse(line[position++]);
       if (lastGatheredResId == -1) { lastGatheredResource = null; }
       else { lastGatheredResource = (Resource)game.GetGameObjectById(lastGatheredResId); }
       // Carrying resource entry
       carryTypeId = line[position++];
       if (carryTypeId == Db.NOENTRY) { carryType = null; }
       else { carryType = Db.Instance.Resources[carryTypeId]; }
       // Carrying resource amount
       carryAmount = int.Parse(line[position++]);
       break;
     case MessageType.GameObjUpdate:
       // Entry
       lastGatheredResId = long.Parse(line[position++]);
       // Last gathered resource
       if (lastGatheredResId == -1) { lastGatheredResource = null; }
       else { lastGatheredResource = (Resource)game.GetGameObjectById(lastGatheredResId); }
       // Carrying resource entry
       carryTypeId = line[position++];
       if (carryTypeId == Db.NOENTRY) { carryType = null; }
       else { carryType = Db.Instance.Resources[carryTypeId]; }
       // Carrying resource amount
       carryAmount = int.Parse(line[position++]);
       break;
     case MessageType.GameObjEntryUpdate:
       entry = Db.Instance.Units[line[position++]].Clone();
       entry.Deserialize(mt, line, ref position, context);
       break;
     case MessageType.GameObjKill:
       break;
     default:
       throw new Exception("Unit deserialization error");
   }
 }
Пример #4
0
    /// <summary>
    /// Constructor of this class
    /// </summary>
    /// <param name="spawner">Building doing the spawning</param>
    /// <param name="spawnee">Unit type to spawn</param>
    /// <param name="owner">Owner of the new unit</param>
    /// <param name="spawnPoint">Position of the new unit</param>
    /// <param name="speed">Spawning speed</param>
    public SpawnerEffect(Building spawner, UnitDb spawnee, Player owner, Vector2 spawnPoint, int speed)
    {
      this.spawner = spawner;
      this.Spawnee = spawnee;
      this.owner = owner;
      this.spawnPoint = spawnPoint;

      this.Speed = speed;
      this.Duration = 0;
    }
Пример #5
0
 /// <summary>
 /// Sets the DbEntry for this unit
 /// </summary>
 /// <param id="newEntry">New DbEntry for this unit</param>
 public void SetDbEntry(IScriptUnitDbEntry newEntry)
 {
   UnitDb newEntryCast = newEntry as UnitDb;
   if (newEntryCast == null) return;
   entry = newEntryCast.Clone();
   entry.ValidateValues();
   game.SendData(Network.MakeServerMessage(MessageType.GameObjEntryUpdate, this));
 }
Пример #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 override void Deserialize(MessageType mt, string[] line, ref int position, WildmenGame context)
 {
   int id;
   base.Deserialize(mt, line, ref position, context);
   switch (mt)
   {
     case MessageType.GameTransfer:
     case MessageType.GameEffectCreate:
       id = int.Parse(line[position++]);
       owner = context.Players.First(p => p.Id == id);
       unitEntry = Db.Instance.Units[line[position++]];
       color = new Color(byte.Parse(line[position++]), byte.Parse(line[position++]), byte.Parse(line[position++]));
       this.position = new Vector2(float.Parse(line[position++], CultureInfo.InvariantCulture), float.Parse(line[position++], CultureInfo.InvariantCulture));
       tile = context.Map.Tiles[int.Parse(line[position++]), int.Parse(line[position++])];
       break;
     default:
       throw new Exception();
   }
 }
Пример #7
0
 /// <summary>
 /// Disposes resources used by this instance
 /// </summary>
 public override void Dispose()
 {
   owner = null;
   unitEntry = null;
   tile = null;
   base.Dispose();
 }
Пример #8
0
    /// <summary>
    /// Constructor of this class
    /// </summary>
    /// <param name="unit">Unit, the death effect should be created from</param>
    public UnitDeathEffect(Unit unit)
    {
      owner = unit.Owner;
      color = owner.PlayerColor;
      unitEntry = (UnitDb)unit.Entry;
      position = unit.Position + unit.AlignmentOffset;
      tile = unit.NearestTile;

      Speed = 10;
      Duration = 10;
      Graphical = true;
    }
Пример #9
0
    /// <summary>
    /// Loads unit 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 LoadUnits(SortedDictionary<string, UnitDb> dict, XDocument xmlFile)
    {
      var unitsXml = xmlFile.Descendants("Unit");
      foreach (var unitXml in unitsXml)
      {
        UnitDb unitEntry = new UnitDb();
        foreach (XNode en in unitXml.Nodes())
        {
          XElement e = en as XElement;
          if (e == null) continue;

          switch (e.Name.LocalName.ToLower())
          {
            case "id": unitEntry.Id = e.Value; break;
            case "name": unitEntry.Name = e.Value; break;
            case "health": unitEntry.Health = int.Parse(e.Value); break;
            case "unitgroup": unitEntry.UnitGroup = int.Parse(e.Value); break;
            case "texture":
              if (!UI.Instance.HaveTexture(e.Value))
              {
                throw new Exception("Entry: " + unitEntry.Id + " - texture " + e.Value + " not found");
              }
              unitEntry.Texture = UI.Instance.GetTexture(e.Value);
              break;
            case "shaman": unitEntry.Shaman = bool.Parse(e.Value); break;
            case "speed": unitEntry.Speed = float.Parse(e.Value, CultureInfo.InvariantCulture); break;
            case "popcount": unitEntry.PopCount = int.Parse(e.Value); break;
            case "givenonstart": unitEntry.GivenOnStart = int.Parse(e.Value); break;
            case "attackrange": unitEntry.AttackRange = int.Parse(e.Value); break;
            case "attackspeed": unitEntry.AttackSpeed = int.Parse(e.Value); break;
            case "attackamount": unitEntry.AttackAmount = int.Parse(e.Value); break;
            case "constructrange": unitEntry.ConstructRange = int.Parse(e.Value); break;
            case "constructspeed": unitEntry.ConstructSpeed = int.Parse(e.Value); break;
            case "constructamount": unitEntry.ConstructAmount = int.Parse(e.Value); break;
            case "gatherrange": unitEntry.GatherRange = int.Parse(e.Value); break;
            case "gatherspeed": unitEntry.GatherSpeed = int.Parse(e.Value); break;
            case "gatheramount": unitEntry.GatherAmount = int.Parse(e.Value); break;
            case "gathercapacity": unitEntry.GatherCapacity = int.Parse(e.Value); break;
            case "modifiers":
              #region
              List<Modifier> modEntries = new List<Modifier>();
              foreach (XElement eModsn in e.Nodes())
              {
                XElement eMods = eModsn as XElement;
                if (eMods == null) continue;

                Modifier modEntry = new Modifier();
                foreach (XNode een in eMods.Nodes())
                {
                  XElement ee = een as XElement;
                  if (ee == null) continue;

                  switch (ee.Name.LocalName.ToLower())
                  {
                    case "unitid": modEntry.EntryUR = ee.Value; break;
                    case "mod": modEntry.Mod = float.Parse(ee.Value, CultureInfo.InvariantCulture); break;
                  }
                }
                modEntries.Add(modEntry);
              }
              unitEntry.Modifiers = modEntries.ToArray();
              #endregion
              break;
          }
        }
        dict.Add(unitEntry.Id, unitEntry);
      }
    }
Пример #10
0
 /// <summary>
 /// Starts unit spawning of given unit at given speed
 /// </summary>
 /// <param name="spawnee"></param>
 /// <param name="speed"></param>
 public void StartUnitSpawner(UnitDb spawnee, int speed)
 {
   SpawnerEffect spawner = new SpawnerEffect(this, spawnee, Owner, MapPosition, speed);
   Spawner = spawner;
   spawner.Initialize(game, NearestTile);
   this.game.Effects.Add(spawner);
   game.SendData(Network.MakeServerMessage(MessageType.GameEffectCreate, spawner));
 }