How to work better with records
https://gist.github.com/IXLLEGACYIXL/e3c5575656de0bebf314096699e9d42c
I have this and want the modified item after breakthrough is applied, but i dont want to modify the original item
but it seems like this shouldnt be the way to work with records... can i simplify that syntax?
42 Replies
your
Apply
method should return the new record instance
so it can't be a voidyes
it was more about the changing of the record itself
you don't change records. you can't without doing some quite evil stuff
also, why are you using full syntax instead of record syntax?
like line 10-13 should this "be the way" its intended to be?
thats the question that i wanted to ask
how to write it in better syntax
whats the record syntax?
or how could i write the lines i have "better" in a better syntax
thats how you declare a record.
if you're going to manually create the props, then why bother with records in the first place?
the reason i dont have it this way is that the engine cant handle it
I don't really understand what you are trying to do, because what you have right now does not work
this does absolutely nothing
imagine it returns targetitem XD
but why is this its own class?
how do you mean?
its just a method. so add it as an extension method, or a normal method
Breakthrough
doesn't add or change anything in ComboDice
because i want a List of "buffs" with for example breakthrough to reduce armor
and imagine that i have
return targetItem....
so i have the original one and a "modified" version
thats an example armor how it should look like in yaml
breakthrough reduces armor and armorincrease increases it
but i dont want to modify "the original armors base" as i apply the buffs in each combat
thats why records as they are good for "keeping the original" and getting a copy that i can modify with the buffsokay, sure
you're gonna have some issues with how the code is written thou.
public ComboDice Base { get; init; } = new ComboDice();
for example
that new ComboDice
does nothing, if Item
is intended to be deserializedoh
in general, records without constructors are not going to work very well here
what would you advise for "modification" and keeping the original
im not sure about yaml deserializers specifically, but the json ones create the object (either via a parameterless ctor or the "best" ctor match) then use reflection to access the property setters
we have yamlsharp from 2008 and my yaml serilaizer that i wrote cant handle it either
how would the API look for this?
ie, how do you "activate" the buffs?
how do you mean?
if i get the collision event from the weapon,
i take the source ( attacking wepaon and character ) and calculate it against the targets armor and character
now all buffs get applied and at the end its just damage - armor
armor would be modified if the weapon has breakthrough so in the last step it would resist less
thats the plan to do
but.. your armor value isnt fixed. its not part of the record
its made by calling the
Roll
methodif my current armor has this as base
{ Rolls : 4 , Side : 8 FIx: 12 }
then the new record will have { Rolls : 4 , Side : 8 FIx: 8 }
with a breakthrough of a roll of 4
if i would calculate now the armors value it would be 4 dices a 8 sides + 8
so its reducedAh I see, so they modify the base roll
they dont make their own rolls
yes
I see.
a 1 roll of 6 sides for armor increase with a result of 3 would increase the armors fix value by 3
after all modifications, the armor rolls with the end result
well then the result of applying all the buffs should be an
IDice
I guess?oh ye
it should be
but even then this seems a bit weird
each buff shouldnt care about the target etc, no? it should only care about the dice its modifying, and itself?
the idea was if you have high fire resistance then ice damages you more
is there an individual stat for ice resistance?
or is fire resistance actually... "heat modifier"?
ie, low values block ice, but make you vulnerable to fire
and vice versa
there is not yet an extra stat for ice
didnt think that far
so an armor would have
Base
Ice
Fire
...
and the buffs as values
hmmm
im playing around with something like this atm
okeeee
lets you apply buffs like this
okeee
i gotta play with that
you could easily send in the source and target char/items here too
falsely understood XD
i have to play with it
i didnt use aggregate too much
the idea is that it takes the base
then sends that to the first buff, gets a result
sends that result to the next buff
repeat until done
that sounds good
yep thats what im going with
ok let me implement another buff and see how it goes
also, currently breakthrough ONLY affects
Fix
so if you give it a value for side or count, it wont do anythingyes