|
Secret
Aug 19, 2018 9:35:36 GMT
via mobile
Post by Thewanderer on Aug 19, 2018 9:35:36 GMT
Hello I went through the tutorial and I am wondering if I could get some help on secrets.
My thought is that it would be cast like a spell creating a secret object attached to the player/hero i added some enums for instance onattacked... And created a triggersecret class. So I cast the card and that sits and listens for that notification that the card has with a switch statement or something? Not quite sure how to design this or how the code would look like because of this.
Thank-you!
|
|
|
Secret
Aug 19, 2018 15:44:50 GMT
Post by Thewanderer on Aug 19, 2018 15:44:50 GMT
Argo posted something about this: I created an abstract AbilityTrigger class that has a list of abilities and a protected ApplyTrigger method that applies the reaction, and a derived class for each game action that can trigger reactions. The TriggerSystem class adds and removes abilities to each of these derived classes as minions/abilities enter/exit play via summon, death, polymorph, silence etc.
I dont understand - does that mean for each gameaction he created a class - like drawcardactiontrigger which had a parent of that gameaction and AbilityTrigger?
then the triggersystem has each of these actions on which will call the applytrigger of whichever action to apply to the reaction?
so then in the json file - you would have a drawcardactiontrigger ability which would also have a trigger string like OnSummonMinion or something
so this would give the minion the drawcardsactiontrigger which every time a minion is summon causes a drawcardaction to occur?
|
|
|
Secret
Aug 20, 2018 7:41:55 GMT
Post by Thewanderer on Aug 20, 2018 7:41:55 GMT
for ability trigger - something like this? assuming abilities contains a list of abilities public abstract class AbilityTrigger { public List<Abilities> abilities;
protected void ApplyTrigger() { }
}
what owns this? will the hero have a list of abilityTriggers?
|
|
|
Secret
Aug 20, 2018 13:36:39 GMT
Post by Admin on Aug 20, 2018 13:36:39 GMT
Great questions... I'll try to help. Here is one way to think about programming architecture- how can you express yourself most efficiently so that you don't have to work as hard? It's not always about what is right or wrong, if your code "works" at all I wouldn't call it wrong, so if you can make something work with an enum, then that is fine. However, there are patterns that allow you to say the same things with less work. For example, you knew that there could be a variety of types of triggers that could cause a secret to respond, so you thought about organizing them via the enum. But then you might start wondering what the implementation of that would look like. Do you need switch statements everywhere you use the trigger? How long will the switch statement grow as you add more kinds of triggers? If that starts to sound like a lot of work then you might look for another pattern.
An alternate pattern is the component pattern. You can create a "trigger" as a component and if you attach it to an object, then the object has that trigger. If you don't attach it, then the object doesn't have that trigger. You can add as many types of triggers as you want, without worrying about expanding switch statements everywhere the trigger is used. The trigger attached as a component can have its own set of variables and or methods that allow it to work independently or with another system (depends on your preferred architecture). A separate system to manage them will be more powerful, but will also require a better mastery of programming to really understand. Try to imagine that the secret is just a variation of another system you have already seen me implement in the card game, and copy as much as you can until you have something working.
You should be able to implement the component pattern either via MonoBehaviour attached to GameObjects, or better still, using my Aspect Container code that I wrote for this project. The trigger can be a kind of Aspect on the Card which is the Container. Then various systems can observe actions that occur in the game, scan for any active trigger, and update an action system with the trigger's target response. Does that help?
|
|
|
Secret
Aug 21, 2018 9:50:51 GMT
Post by Thewanderer on Aug 21, 2018 9:50:51 GMT
I am trying to figure this system out more and more
Secrets are cards - IE type would equal Secret instead of Spell so that would make the Secret a Card
the Secret Type Card would contain a Trigger string for the Enum to be parsed ( i am unsure if this would cause some issues with other cards that do not have the Trigger string )
the Card would attach to a Hero - public List<Secret> Secrets; to the hero
I could then use the SecretSystem to activate the 'Ability' of the Secret upon whatever actions cause triggers alternatively i think i see what you mean about the aspect container - i would make it an aspect - like the taunt ability...and what i can do is for each action put in a checkforsecrets method in each of their systems that will check for in game secrets then create a secretaction that would carry out other actions from the secretsystem which would mainly be abilityaction and carry out the ability.
i think it does help thank you! - hope i understand correctly, ill let you know if it works.
|
|
|
Secret
Aug 21, 2018 10:34:21 GMT
Post by Thewanderer on Aug 21, 2018 10:34:21 GMT
deckfactory i have added
AddTriggers(card, cardData);
then
private static void AddTriggers(Card card, Dictionary<string, object> data) { if (data.ContainsKey("Trigger")) { card.AddAspect<Trigger>(); } }
so far ... what i am thinking to do is have a separate Secret card and will have this trigger aspect and what i will do is create a new action that will be specific for the trigger actions so that i can control trigger abilities and non trigger abilities when i need.
will provide further code which i get done with some more
|
|
|
Secret
Aug 21, 2018 13:21:24 GMT
Post by Admin on Aug 21, 2018 13:21:24 GMT
Sounds like a good start, I'll look forward to seeing what you can do
|
|
|
Secret
Aug 23, 2018 0:26:10 GMT
Post by Legend on Aug 23, 2018 0:26:10 GMT
Here is how i am doing it
private static void AddtriggeredSelector(TriggeredAbility tability, Dictionary<string, object> data) { if (data.ContainsKey("targetSelector") == false) return; var selectorData = (Dictionary<string, object>)data["targetSelector"]; var typeName = (string)selectorData["type"]; var type = Type.GetType(typeName); var instance = Activator.CreateInstance(type) as ITargetSelector; instance.Load(selectorData); tability.AddAspect<ITargetSelector>(instance); }
look at the tauntsystem
and you may not even need to derive any gameactions with this
void OnPerformtAbilityAction(object sender, object args) { var action = args as TriggeredAbilityAction; var type = Type.GetType(action.tability.actionName); var instance = Activator.CreateInstance(type) as GameAction; var loader = instance as IAbilityLoader; if (loader != null) { var ability = new Ability { actionName = action.tability.actionName, userInfo = action.tability.userInfo, container = action.tability.container };
loader.Load(container, ability); } container.AddReaction(instance); }
set that - make triggered abilities aspect with lisst of triggered abiltiies - i created a system for each action that listens for each action and a triggeredabilitysystem that performs the action that is within the JSON - basically it just takes the triggeredability information and creates an ability based off the actionname which should just be the ability action....
|
|
|
Secret
Aug 23, 2018 0:34:06 GMT
Post by Legend on Aug 23, 2018 0:34:06 GMT
Actually just going over this you could technically just pop this into each of the already existing systems as its only 2 additional methods you need since you can create a a triggeredability class to inherit off of that will act as the majority of the work
|
|