public Hero(Vector2 position, Spell[] spells) { Position = position; Health = MaxHealth; Spells = new Spell[spells.Length]; spells.CopyTo(Spells, 0); }
public Notification Deserialize(byte[] data) { string asText = Encoding.GetString(data); string[] input = asText.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); NotificationType type = (NotificationType)int.Parse(input[0]); int id = int.Parse(input[1]); switch (type) { case NotificationType.Position : Vector2 position = new Vector2(Single.Parse(input[2]), Single.Parse(input[3])); return Notification.CreatePosition(id, position); case NotificationType.SpellCast : Spell spell = new Spell(int.Parse(input[2])); return Notification.CreateSpellCast(id, spell); case NotificationType.GameStarting: int[] indices = new int[input.Length - 2]; for (int i = 0; i < indices.Length; i++) { indices[i] = int.Parse(input[i + 2]); } return Notification.CreateGameStarted(id, indices); default: string text = input.Skip(2).Aggregate(string.Empty, (x, y) => x + " " + y); return Notification.CreateFromTextType(id, text, type); }; }
public static Notification CreateSpellCast(int id, Spell spell) { return new Notification(id, spell, NotificationType.SpellCast); }
public void CastSpell(int id, Spell spell) { this.players[id].Spells.First(index => spell.Id == index.Id).LastUsage = DateTime.UtcNow; this.castSpells.Add(new Magic(spell.Id, this.players[id].Position)); }