Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add serialized tag so game can be brought down to binary or xml #181

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions SabberStoneCore/src/Auras/AdaptiveCostEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace SabberStoneCore.Auras
/// <summary>
/// Implementation of the specific effects of varying cost. e.g. Giants
/// </summary>
[Serializable]
public class AdaptiveCostEffect : IAura
{
// Consider make these subclasses
Expand Down
1 change: 1 addition & 0 deletions SabberStoneCore/src/Auras/AdaptiveEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace SabberStoneCore.Auras
/// <summary>
/// Effects of this kind of Auras are influenced by other factors in game, in real time. e.g. Lightspawn, Southsea Deckhand.
/// </summary>
[Serializable]
public class AdaptiveEffect : IAura
{
private readonly bool _isSwitching;
Expand Down
4 changes: 3 additions & 1 deletion SabberStoneCore/src/Auras/AdjacentAura.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using SabberStoneCore.Enchants;
using SabberStoneCore.Enums;
using SabberStoneCore.Kettle;
Expand All @@ -9,6 +10,7 @@

namespace SabberStoneCore.Auras
{
[Serializable]
public class AdjacentAura : IAura
{
private Minion _left;
Expand Down
3 changes: 3 additions & 0 deletions SabberStoneCore/src/Auras/Aura.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ namespace SabberStoneCore.Auras
/// Aura must be activated first to affect entities.
/// The effect of an aura is applied or removed during <see cref="SabberStoneCore.Model.Game.AuraUpdate"/>.
/// </summary>
[Serializable]
public class Aura : IAura
{
private protected enum Instruction
{
Invalid, RemoveAll, AddAll, Add, Remove, /*CheckAdjacency*/
}

[Serializable]
private protected readonly struct AuraUpdateInstruction : IEquatable<AuraUpdateInstruction>
{
public readonly IPlayable Src;
Expand Down
4 changes: 3 additions & 1 deletion SabberStoneCore/src/Auras/EnrageEffect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using System.Text;
using SabberStoneCore.Actions;
using SabberStoneCore.Enchants;
Expand All @@ -10,6 +11,7 @@ namespace SabberStoneCore.Auras
/// <summary>
/// Implementation of the Enrage effect.
/// </summary>
[Serializable]
public class EnrageEffect : Aura
{
private bool _enraged;
Expand Down
4 changes: 3 additions & 1 deletion SabberStoneCore/src/Auras/MultiAura.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using SabberStoneCore.Enchants;
Expand All @@ -9,6 +10,7 @@ namespace SabberStoneCore.Auras
/// <summary>
/// A container class for multiple auras. Use this when you want to implement a <see cref="Power"/> with multiple auras.
/// </summary>
[Serializable]
public class MultiAura : IAura, IReadOnlyList<IAura>
{
private readonly IReadOnlyList<IAura> _auras;
Expand Down
4 changes: 3 additions & 1 deletion SabberStoneCore/src/Auras/SummoningPortalAura.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using SabberStoneCore.Model.Entities;
using System;
using SabberStoneCore.Model.Entities;

namespace SabberStoneCore.Auras
{
[Serializable]
public class SummoningPortalAura : Aura
{
public SummoningPortalAura() : base(AuraType.HAND) { }
Expand Down
1 change: 1 addition & 0 deletions SabberStoneCore/src/Auras/SwitchingAura.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace SabberStoneCore.Auras
{
[Serializable]
public class SwitchingAura : Aura
{
private readonly SelfCondition _initialisationCondtion;
Expand Down
2 changes: 2 additions & 0 deletions SabberStoneCore/src/Conditions/RelaCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ namespace SabberStoneCore.Conditions
/// Container for all conditions about the relation between 2 <see cref="IPlayable"/>
/// instances.
/// </summary>
[Serializable]
public class RelaCondition
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
{
[NonSerialized]
private readonly Func<IPlayable, IPlayable, bool> _function;

public static RelaCondition IsMyWeapon => new RelaCondition((me, other) => me.Controller.Hero.Weapon != null && me.Controller.Hero.Weapon == other);
Expand Down
145 changes: 105 additions & 40 deletions SabberStoneCore/src/Conditions/SelfCondition.cs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions SabberStoneCore/src/Config/GameConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace SabberStoneCore.Config
/// <summary>
/// Holds all configuration values to create a new <see cref="Game"/> instance.
/// </summary>
[Serializable]
public class GameConfig
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions SabberStoneCore/src/Enchants/AuraEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace SabberStoneCore.Enchants
/// <summary>
/// A simple container for saving tag value perturbations from external Auras. Call indexer to get value for a particular Tag.
/// </summary>
[Serializable]
public class AuraEffects : IEquatable<AuraEffects>
{
private const int PlayableLength = 2;
Expand Down Expand Up @@ -354,6 +355,7 @@ public override int GetHashCode()
/// A collecton of controller Tag increments from Auras.
/// These tags tends to be checked when a player plays any cards.
/// </summary>
[Serializable]
public class ControllerAuraEffects : IEquatable<ControllerAuraEffects>
{
private Action<IPowerHistoryEntry> _sendHistory;
Expand Down
1 change: 1 addition & 0 deletions SabberStoneCore/src/Enchants/Effect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public interface IEffect
/// <summary>
/// A structure for tag value variation.
/// </summary>
[Serializable]
public readonly struct Effect : IEffect, IEquatable<Effect>
{
public readonly GameTag Tag;
Expand Down
2 changes: 2 additions & 0 deletions SabberStoneCore/src/Enchants/Enchant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace SabberStoneCore.Enchants
/// <summary>
/// Class to store attributes of the <see cref="Power"/> of an Enchantment Card.
/// </summary>
[Serializable]
public class Enchant
{
public static readonly Trigger RemoveWhenPlayedTrigger =
Expand Down Expand Up @@ -134,6 +135,7 @@ public void RemoveEffect(in IEntity target, int num1, int num2)
/// OngoingEnchant is narrowly used when the source of the trigger and
/// the target of the Enchantment is identical. (e.g. Mana Wyrm)
/// </summary>
[Serializable]
public class OngoingEnchant : Enchant, IAura
{
public Game Game;
Expand Down
2 changes: 2 additions & 0 deletions SabberStoneCore/src/Enchants/Enchants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace SabberStoneCore.Enchants
{
[Serializable]
internal static class Enchants
{
private static Regex AttackHealth = new Regex(@"[+](\d)[/][+](\d)");
Expand Down Expand Up @@ -162,6 +163,7 @@ public static Enchant GetAutoEnchantFromText(string cardId)

}

[Serializable]
internal static class Effects
{
internal static IEffect Attack_N(int n)
Expand Down
12 changes: 12 additions & 0 deletions SabberStoneCore/src/Enchants/GenericEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace SabberStoneCore.Enchants
{
[Serializable]
internal readonly struct GenericEffect<TAttr, T> : IEffect where TAttr : Attr<T> where T : Playable
{
private readonly TAttr _attr;
Expand Down Expand Up @@ -87,6 +88,7 @@ public override string ToString()
}
}

[Serializable]
internal abstract class Attr<T> where T : Playable
{
public abstract void Apply(T entity, EffectOperator @operator, int value);
Expand All @@ -98,6 +100,7 @@ internal abstract class Attr<T> where T : Playable
protected abstract ref int GetAuraRef(AuraEffects auraEffects);
}

[Serializable]
internal abstract class IntAttr<T> : Attr<T> where T : Playable
{
protected abstract ref int? GetRef(T entity);
Expand Down Expand Up @@ -204,6 +207,7 @@ public override void RemoveAura(T entity, EffectOperator @operator, int value)
}
}

[Serializable]
internal abstract class BoolAttr<T> : Attr<T> where T : Playable
{
protected abstract ref bool? GetRef(T entity);
Expand Down Expand Up @@ -243,6 +247,7 @@ public override void RemoveAura(T entity, EffectOperator @operator, int value)
}
}

[Serializable]
internal abstract class SelfContainedIntAttr<TSelf, TTarget> : IntAttr<TTarget>
where TSelf : SelfContainedIntAttr<TSelf, TTarget>, new() where TTarget : Playable
{
Expand All @@ -254,6 +259,7 @@ public static GenericEffect<TSelf, TTarget> Effect(EffectOperator @operator, int
}
}

[Serializable]
internal abstract class SelfContainedBoolAttr<TSelf, TTarget> : BoolAttr<TTarget>
where TSelf : SelfContainedBoolAttr<TSelf, TTarget>, new() where TTarget : Playable
{
Expand All @@ -265,6 +271,7 @@ public static GenericEffect<TSelf, TTarget> Effect(bool value = true)
}
}

[Serializable]
internal class Cost : SelfContainedIntAttr<Cost, Playable>
{
public override GameTag Tag => GameTag.COST;
Expand Down Expand Up @@ -309,6 +316,7 @@ public override void RemoveAura(Playable entity, EffectOperator @operator, int v
}
}

[Serializable]
internal class ATK : SelfContainedIntAttr<ATK, Playable>
{
public override GameTag Tag => GameTag.ATK;
Expand Down Expand Up @@ -365,6 +373,7 @@ public override void Apply(Playable entity, EffectOperator @operator, int value)
//}
}

[Serializable]
internal class Health : SelfContainedIntAttr<Health, Character>
{
public override GameTag Tag => GameTag.HEALTH;
Expand Down Expand Up @@ -417,6 +426,7 @@ public override void RemoveAura(Character entity, EffectOperator @operator, int
}
}

[Serializable]
internal class Stealth : SelfContainedBoolAttr<Stealth, Character>
{
public override GameTag Tag => GameTag.STEALTH;
Expand All @@ -432,6 +442,7 @@ protected override ref int GetAuraRef(AuraEffects auraEffects)
}
}

[Serializable]
internal class Taunt : SelfContainedBoolAttr<Taunt, Minion>
{
public override GameTag Tag => GameTag.TAUNT;
Expand All @@ -447,6 +458,7 @@ protected override ref int GetAuraRef(AuraEffects auraEffects)
}
}

[Serializable]
internal class CantBeTargetedBySpells : SelfContainedBoolAttr<CantBeTargetedBySpells, Character>
{
public override GameTag Tag => GameTag.CANT_BE_TARGETED_BY_SPELLS;
Expand Down
2 changes: 2 additions & 0 deletions SabberStoneCore/src/Enchants/Power.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// GNU Affero General Public License for more details.
#endregion

using System;
using SabberStoneCore.Auras;
using SabberStoneCore.Enums;
using SabberStoneCore.Tasks;
Expand All @@ -20,6 +21,7 @@

namespace SabberStoneCore.Enchants
{
[Serializable]
public class Power
{
public string InfoCardId { get; set; } = null;
Expand Down
1 change: 1 addition & 0 deletions SabberStoneCore/src/Kettle/PowerHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public static PowerHistoryBlockEnd BlockEnd()
// }
// repeated PowerHistoryData list = 1;
//}
[Serializable]
public class PowerHistory
{
public List<IPowerHistoryEntry> Full { get; } = new List<IPowerHistoryEntry>();
Expand Down
1 change: 1 addition & 0 deletions SabberStoneCore/src/Loader/TargetingPredicates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace SabberStoneCore.Loader
public delegate bool AvailabilityPredicate(Controller controller, Card card);
public delegate bool TargetingPredicate(ICharacter target);

[Serializable]
public static class TargetingPredicates
{
private static readonly TargetingPredicate ReqMurlocTarget
Expand Down
1 change: 1 addition & 0 deletions SabberStoneCore/src/Model/Card.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace SabberStoneCore.Model
/// All properties exposed by these instances are defined by `resources/Data/CardDefs.xml`.
/// <see cref="CardLoader"/> for extraction procedures.
/// </summary>
[Serializable]
public sealed class Card
{
/// <summary>
Expand Down
1 change: 1 addition & 0 deletions SabberStoneCore/src/Model/Choice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public enum ChoiceAction
/// <summary>
///
/// </summary>
[Serializable]
public class Choice
{
/// <summary>Initializes a new instance of the <see cref="Choice"/> class.</summary>
Expand Down
1 change: 1 addition & 0 deletions SabberStoneCore/src/Model/Entities/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public partial interface ICharacter : IPlayable
/// <seealso cref="ICharacter"/>
/// <seealso cref="Playable"/>
/// </summary>
[Serializable]
public abstract partial class Character : Playable, ICharacter
{
public event TriggerManager.TriggerHandler PreDamageTrigger;
Expand Down
1 change: 1 addition & 0 deletions SabberStoneCore/src/Model/Entities/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace SabberStoneCore.Model.Entities
/// Instance that represents a player in SabberStone game instances.
/// <seealso cref="Entity"/>
/// </summary>
[Serializable]
public partial class Controller : Entity
{
private readonly int _playerId;
Expand Down
1 change: 1 addition & 0 deletions SabberStoneCore/src/Model/Entities/Enchantment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace SabberStoneCore.Model.Entities
{
[Serializable]
public partial class Enchantment : IPlayable
{
private readonly EntityData _tags;
Expand Down
1 change: 1 addition & 0 deletions SabberStoneCore/src/Model/Entities/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public interface IEntity : IEnumerable<KeyValuePair<GameTag, int>>
/// <seealso cref="Spell"/>
/// </summary>
/// <seealso cref="IEntity" />
[Serializable]
public partial class Entity : IEntity
{
/// <summary>
Expand Down
1 change: 1 addition & 0 deletions SabberStoneCore/src/Model/Entities/EntityData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace SabberStoneCore.Model.Entities
/// Implements <see cref="IDictionary{TKey, TValue}"/>.
/// This only contains modified/added tags during runtime, rather than card's original tags.
/// </summary>
[Serializable]
internal class EntityData : IDictionary<GameTag, int>
{
private const int _initSize = 16;
Expand Down
1 change: 1 addition & 0 deletions SabberStoneCore/src/Model/Entities/EntityList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace SabberStoneCore.Model.Entities
/// Implements <see cref="IDictionary"/>.
/// </summary>
[DebuggerDisplay("Count = {_count}")]
[Serializable]
public class EntityList : IDictionary<int, IPlayable>
{
private IPlayable[] _list;
Expand Down
3 changes: 3 additions & 0 deletions SabberStoneCore/src/Model/Entities/Hero.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using SabberStoneCore.Auras;
Expand All @@ -23,6 +25,7 @@ namespace SabberStoneCore.Model.Entities
/// </summary>
/// <seealso cref="Character" />
/// <autogeneratedoc />
[Serializable]
public partial class Hero : Character
{
/// <summary>Gets or sets the hero power entity.</summary>
Expand Down
3 changes: 3 additions & 0 deletions SabberStoneCore/src/Model/Entities/HeroPower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
#endregion

using System;
using System.Collections.Generic;
using SabberStoneCore.Enums;

Expand All @@ -20,6 +22,7 @@ namespace SabberStoneCore.Model.Entities
/// Entity representing the special ability for a hero.
/// </summary>
/// <seealso cref="Playable" />
[Serializable]
public class HeroPower : Playable
{
/// <summary>Initializes a new instance of the <see cref="HeroPower"/> class.</summary>
Expand Down
Loading