/// <summary> /// Creates a new, unique clone of the spell. /// Uses the effect metadata to create new instances of /// effects too. /// </summary> /// <param name="owner"></param> /// <returns></returns> public Spell CreateInstance(Player owner) { var spell = new Spell { ID = ID, TargetType = TargetType, TargetGroup = TargetGroup, UID = SID.New() }; foreach (var effect in EffectData) { // Need to create a new instance of effect for every spell! spell.Effects.Add(Game.SpellEffects.CreateInstance(effect.Name, effect.Attributes)); } return spell; }
static void Main(string[] args) { Console.WriteLine("Card Game Server Initialising.."); Console.WriteLine("Protocol Version: " + GameActionWriter.PROTOCOL_VERSION); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Loading Data.."); Console.ForegroundColor = ConsoleColor.Yellow; // Load in all the game data (xml) Game.Load(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Starting Server.."); Console.ForegroundColor = ConsoleColor.White; var p = new Player(); var test = Game.Spells["frostbolt"].CreateInstance(p); var test2 = Game.Spells["deepfreeze"].CreateInstance(p); Console.WriteLine(test.GetDescription()); Console.WriteLine(test2.GetDescription()); // Start the listen server and wait for connections! Server.Start(); }
// Use a template model ? // -> Load creature data externally // -> Create an instance of this creature class for each creature in database // -> Set appropriate attributes and add effects (based on data) // -> Create deep clone using this function when we want to make a usable copy public Creature CreateInstance(Player owner, bool commander, int team) { var newCreature = new Creature { ID = ID, Description = Description, Name = Name, BaseHealth = BaseHealth, Damage = Damage, Team = team, Commander = commander, SleepSickness = SleepSickness, CanAttack = CanAttack, Taunt = Taunt, MagicImmune = MagicImmune, PhysicalImmune = PhysicalImmune, Stealth = Stealth, AttackDamageType = AttackDamageType, Owner = owner, Image = Image, UID = SID.New() }; foreach (var effect in EffectData) { // Need to create a new instance of effect for every creature! newCreature.Effects.Add(Game.CreatureEffects.CreateInstance(effect.Name, effect.Attributes)); } return newCreature; }
/// <summary> /// Generates a list of targets from the spell and player data, /// then casts the spell on them. /// </summary> /// <param name="player">Player who is casting spell</param> /// <param name="spell">Spell to cast</param> /// <param name="pickedTarget">The creature/commander to target with spell, if needed.</param> /// <returns>True if spell cast started (even if spell was blocked), false if invalid target given.</returns> public bool Cast(Player player, Spell spell, Creature pickedTarget = null) { var targets = GetPossibleTargets(player, spell); switch (spell.TargetType) { case TargetType.Random: Cast(spell, new List<Creature> { targets[ServerRandom.Generator.Next(targets.Count)] }); return true; case TargetType.Single: if (targets.Contains(pickedTarget)) { Cast(spell, new List<Creature> { pickedTarget }); return true; } return false; case TargetType.None: Cast(spell, targets); return true; default: throw new ArgumentOutOfRangeException(); } }
protected virtual void OnTurnStart(Board arg1, Player arg2) { var handler = TurnStart; handler?.Invoke(arg1, arg2); }
// TODO: Finish the actual game logic! public void Summon(Player owner, Creature creature) { Console.WriteLine("SUMMONING: " + creature.Name); }
/// <summary> /// Handles a GameAction command sent by a player. /// </summary> /// <param name="player">The player that sent the command</param> /// <param name="action">What type of action it is</param> /// <param name="data">The data, such as who to target or the player's name</param> public void RecieveCommand(Player player, GameDataAction dataAction) { // TODO: Finish the command recieved events var data = dataAction.Data; var action = dataAction.Action; if (player == ActivePlayer) { switch (action) { case GameAction.TurnEnd: EndTurn(null); break; case GameAction.PlayCard: Card card; // Attempt to get the card matching the UID if (player.Cards.TryGetValue(data["uid"], out card)) { GameData targetID; if (data.TryGetValue("target", out targetID)) { } card.Play(); } break; case GameAction.GameStart: break; case GameAction.TurnStart: break; case GameAction.DrawCard: break; case GameAction.SetMana: break; case GameAction.SetHealth: break; case GameAction.Attack: break; case GameAction.Trigger: break; case GameAction.Kill: break; case GameAction.MinionSummoned: break; case GameAction.SpellCast: break; case GameAction.GameOver: break; case GameAction.Meta: break; case GameAction.Ping: break; default: throw new ArgumentOutOfRangeException(nameof(action), action, null); } } }
/// <summary> /// Builds up a list of possible targets for the given spell and player. /// </summary> /// <param name="owner">Owner of the spell</param> /// <param name="spell">Spell in question</param> /// <returns></returns> public List<Creature> GetPossibleTargets(Player owner, Spell spell) { var creatures = new List<Creature>(); if (spell.TargetGroup.IsFlagSet(TargetGroup.None)) { return creatures; } if (spell.TargetGroup.IsFlagSet(TargetGroup.Champions)) { if (spell.TargetGroup.IsFlagSet(TargetGroup.Allies)) { creatures.Add(owner.Commander); } if (spell.TargetGroup.IsFlagSet(TargetGroup.Enemies)) { creatures.AddRange(from p in Players where p != owner select p.Commander); } } if (!spell.TargetGroup.IsFlagSet(TargetGroup.Minions)) return creatures; if (spell.TargetGroup.IsFlagSet(TargetGroup.Allies)) { creatures.AddRange(owner.Creatures.Where(c => !c.Commander)); } if (spell.TargetGroup.IsFlagSet(TargetGroup.Enemies)) { creatures.AddRange(from p in Players from c in p.Creatures where !c.Commander select c); } return creatures; }
private void DrawCard(Player activePlayer) { var drawnCard = activePlayer.Deck.Pop(); activePlayer.Cards.Add(drawnCard.UID, drawnCard); drawnCard.Effects.ForEach(x => x.Start(drawnCard)); // Show the player what card they have drawn activePlayer.DataWriter.SendAction(GameAction.DrawCard, new Dictionary<string, GameData>() { // TODO: Send modifiers {"player", ActivePlayerID}, {"card", drawnCard.ID}, {"uid", drawnCard.UID.ToString()} }); // Tell the other players that a card has been drawn SendToInactivePlayers(GameAction.DrawCard, new Dictionary<string, GameData> { {"player", ActivePlayerID}, {"card", "-1"} }); }