/// <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.GameEffectCreate: spawner = (Building)context.GetGameObjectById(int.Parse(line[position++])); ((Building)spawner).ResetSpawner(this); Spawnee = Db.Instance.Units[line[position++]]; int playerId = int.Parse(line[position++]); owner = context.Players.First(u => u.Id == playerId); spawnPoint = new Vector2(float.Parse(line[position++], CultureInfo.InvariantCulture), float.Parse(line[position++], CultureInfo.InvariantCulture)); break; default: throw new Exception(); } }
/// <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"); } }