arphile

Member
Spider`s Silk is a part of Reagents, but how can I put in values?

I want to put in like this.

Item obj = new SpiderSilk();
// and some codes in here, it makes obj to Reagent

Item obj2 = new Garlic();
if ( obj2 is obj ) { // now obj is Reagent, so it will be like this : if ( obj2 is Reagent )
~~~
}

is anyone have a solution about this problem?
 
I´m not sure what you try to gain by it.
Silk and Garlic are Reagents but Silk is not Garlic and Garlic is not silk. So this is not the direction you want maybe.

If you Generate a Silk and ask if its reagent it will work but not if its reagent.

You could say "ok i cast to reagent" and do Reagent Obj2 = obj1 as Reagent.
But Obj2 is never Obj3 as Type. Only if both would be Garlic.

You should explain what benefits you try to gain by doing this. Your sample looks for me a bit like nonsense. Why should i create Silk with uses 10 and then Cast it to Garlic?
Why not make Silk with uses of Garlic?

When i were learning courses my teacher always said "Pets are global, a dog is a pet , a horse as well, but a dog cant never been a horse"
 
if (obj1 is Reagent && obj2 is Reagent)

not sure what you are trying to check :/

if you compare spidersilk to garlic, both are not the same.
garlic and spidersilk inherit from reagent, so it would be right to compare both to Reagent.
 
if (obj1 is Reagent && obj2 is Reagent)

not sure what you are trying to check :/

if you compare spidersilk to garlic, both are not the same.
garlic and spidersilk inherit from reagent, so it would be right to compare both to Reagent.

yeah, what I want to is make Gaelic to just Reagent.
I tried to using like Item.GetType().GetType()
but it doesn`t work...
 
yeah, what I want to is make Gaelic to just Reagent.
I tried to using like Item.GetType().GetType()
but it doesn`t work...

Garlic is a Reagent!

Basic of Inheritence => Sample :

A Sword inherits from BaseMeleeWeapon, means its a sword and a BaseMeleeWeapon. Basemeleeweapon inherits from BaseWeapon, so Swords are also BaseWeapons. BaseWeapon inherit from Item, its also an Item.

If you want to check if (Sword is Item) it will returns true. If you create a Bow and ask if(Bow is Sword) its wrong. but you can ask if(bow is Item) and then its right again.

GetType() reflects the Top-designed ObjectType.

If you want to create a List and later manipulate your data you could make a List<Reagents> then put in Garlic, Silk, Mandrake and every kind what inherits from Reagents. If you want to mix multiple types you could create a List<Item> and later filter to the shared type like :
if(Entry is Reagent) { Reagent e = Entry as Reagent; e.Amount = 10} you can do all this kind as long as you not try to convert an object to a not possible being (making Garlic to reagent then cast to Item and then cast to sword would be impossible)

What i currently do a lot for dynamic activation :

Item myItem = Activator.CreateInstance(typeof(Katana)) as Item;
if(myItem is BaseMeleeWeapon)
{
BaseMeleeWeapon wpn = myItem as BaseMeleeWeapon;
wpn.WeaponAttributes.HitLifeLeech = 30;
}

Create default Instance as Item (for Types they are 100% an Item) then filter to common shared types to get access to attributes i want to manipulate. Then cast it to the common shared type and modify the data. MyItem is still a complex object, changes on the wpn attributes are linked to myItem, since its not a copy, its a clone with more attributes and methods.
 
yes I know garlic is BaseReagent.
but it is just example...
I have a lot of types of items, and I need to sort something..
so that`s the reason why I need to use this codes..

I know using like
if ( obj1 is BaseReagent ) {
BaseReagent aa = obj1 as BaseReagent;
}
is very simple answer, but I have many type of bases.

I want reduce codes, so that`s the reason why I need to change obj1 to BaseReagent without casts..

so, I tried .GetType() twice, and base.obj1 .
but it didn`t work...
 
I want reduce codes, so that`s the reason why I need to change obj1 to BaseReagent without casts..

It would be nice if you would tell us what you want to gain by this.

If you not want to cast it why not make it as Basereagent?
BaseReagent myGarlic = new Garlic();

I don´t understand what you try to accomplish and in what kind of way you want to "reduce" code.
As i see this currently it doesnt make any sense for me and the way you described your issue looked like you had an "knowelegde" issue.
 
so, exactly what I want to do is
targetting garlic -> check it is BaseReagent -> Get Type as BaseReagent

Item -> BaseReagent -> Garlic

I know this function, but how can I get BaseReagent just using Garlic?

I want to sort a lot of kind items, and there are many kinds of basetypes.
so, if I type basetypes, it will make too many lines.

that`s the reason why I need to convert garlic to BaseReagent..

I tried target script, and targeting garlic, and then using terget.GerType().GetType()
but it returns RunTime ( I don`t know what is the RunTime )

and tried like base.target.GetType()
but it just convert to targetscript`s base

what I need is targetting garlic, and get BaseReagent.
 
so, exactly what I want to do is
targetting garlic -> check it is BaseReagent -> Get Type as BaseReagent

A Type is a declarion what kind of Object you have. you cant get a Type as SubType.
You can cast or check if an object is typeof(X) or inherited from X.

In the Moment you Target Garlic you can check if the ITem is Garlic, or Is BaseReagent or is Item.
All 3 will return true because Garlic is also BaseReagent and also Item

Sample from Real World :
You have Animals, some Animals could be Horses and some Horses can be special races.
No matter from qhat perspective you look. A Special Race cant be another special race, but they
are always Horses and always animals.

You dont make an instance into an Type, you compare same beings and use Attributes of same beeings.

I know this function, but how can I get BaseReagent just using Garlic?
I want to sort a lot of kind items, and there are many kinds of basetypes.
so, if I type basetypes, it will make too many lines.
This is not a Function, this is a basic of object orientated programming,
Inheritence and Polymorphy as sample.
As i stated above Garlic is ALSO BaseReagent. If you take any list\Array with the type of BaseReagent,
you can put any Object into, wich inherits from BaseReagent.

The Hirarchy is here topdown :

Items -> BaseReagent -> Garlic as said above.
The deepness how you filter depending on you. You also could just filter for Items and Mobiles and then make subfilter\Sublists.

You also can´t prevent many lines if you check many things. You also can´t avoid getting fat if you eat many food. (Yes Sport but then you have to do "a lot of sport")

that`s the reason why I need to convert garlic to BaseReagent..
As said above its already a BaseReagent. You can cast it back, but then you loose the Properties you may added to Garlic.
As sample with my animals :
Animals have the function to breed, eat, and such. But you say your horse can be tamed.
You cant check if an Animal is tamed, but you can check if a horse is tamed.
So "CASTING" it back only removes abilities and properties on the moment you want to handle the fatherclass, but the informations arent lost,
even if you cast it back to an animal, its theoreticly still a horse.


I tried target script, and targeting garlic, and then using terget.GerType().GetType()
but it returns RunTime ( I don`t know what is the RunTime )
and tried like base.target.GetType()
but it just convert to targetscript`s base
what I need is targetting garlic, and get BaseReagent.
Target an Object and check if its Mobile or Item
if you know its an item you can check if its a BaseReagent
by using GetType() you get the actual top object type, but as said its still BaseReagent
base.target.getType() is not right here.
You call the father then a Target and then want a type?
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back